ranks[$myFirm->id] as $rank) { if($rank->id==0) continue; $rankIds[] = $rank->id; } $sql = 'SELECT * FROM {{table}} p WHERE p.owner = ? OR p.id IN(SELECT s.planning FROM '.PlanningShare::tableName().' s WHERE (recipient = ? AND recipientEntity="user") '; if(count($rankIds)>0) $sql .= ' OR (recipient IN('.implode(',',$rankIds).') AND recipientEntity="rank" )'; $sql .= ')'; $plannings = Planning::staticQuery($sql,array($myUser->login,$myUser->login),true); $selectedPlannings = json_decode($myUser->preference('planning_selected_calendars'),true); $selectedPlannings = !is_array($selectedPlannings) ? array() : $selectedPlannings; if(count($plannings)==0){ $item = Planning::provide(); $item->label = 'Général'; $item->color = '#17a2b8'; $item->owner = $myUser->login; $item->type = 'local'; $item->default = true; $item->slug = slugify($item->label); $item->save(); $plannings[] = $item; } Plugin::callHook('planning_planning_search',array(&$plannings,&$selectedPlannings)); usort($plannings, function($a,$b){ global $myUser; if($a->owner == $myUser->login) return -1; return 1; }); foreach($plannings as $planning){ $row = $planning->toArray(); if(in_array($planning->id, $selectedPlannings)) $row['selected'] = true; if($conf->get('planning_show_default')!==true && $planning->default) continue; $row['editable'] = $planning->owner != $myUser->login ? false : true; $row['shared'] = $row['owner'] != $myUser->login; $row['ownerName'] = User::byLogin($row['owner'])->fullName(); $response['rows'][] = $row; } }); break; case 'planning_edit': global $myUser,$_; User::check_access('planning','edit'); require_once(__DIR__.SLASH.'planning.modal.php'); break; //Ajout ou modification d'élément planning case 'planning_save': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','edit'); require_once(__DIR__.SLASH.'Planning.class.php'); $item = Planning::provide(); if($item->id!=0 && $item->owner != $myUser->login && !$myUser->superadmin) throw new Exception("Seul le propriétaire de ce planning peut le modifier"); $item->label = $_['planning-label']; $item->color = $_['planning-color']; $item->owner = $myUser->login; $item->type = 'local'; $item->save(); }); break; //Suppression d'élement planning case 'planning_delete': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','delete'); require_once(__DIR__.SLASH.'Planning.class.php'); require_once(__DIR__.SLASH.'PlanningEvent.class.php'); require_once(__DIR__.SLASH.'PlanningShare.class.php'); $planning = Planning::provide(); if(!$planning) throw new Exception("Planning inexistant"); if($planning->default) throw new Exception("Vous ne pouvez pas supprimer le planning par défaut"); if($planning->owner != $myUser->login && !$myUser->superadmin) throw new Exception("Vous ne pouvez pas supprimer un planning dont vous n'êtes pas le propriétaire"); Planning::deleteById($planning->id); PlanningEvent::delete(array('planning'=>$planning->id)); PlanningShare::delete(array('planning'=>$planning->id)); }); break; case 'planning_widget_load': global $myUser; require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php'); $widget = DashboardWidget::current(); $widget->title = 'Mes 10 prochains rendez vous'; ob_start(); require_once(__DIR__.SLASH.'widget.php'); $widget->content = ob_get_clean(); echo json_encode($widget); break; /** PLANNINGEVENT **/ //Récuperation d'une liste de planningevent case 'planning_event_search': Action::write(function(&$response){ global $myUser,$_,$myFirm,$conf; User::check_access('planning','read'); require_once(__DIR__.SLASH.'Planning.class.php'); require_once(__DIR__.SLASH.'PlanningEvent.class.php'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); if(!isset($_['plannings'])) return; $plannings = $_['plannings']; $start = strtotime($_['start']); $end = strtotime($_['end']); $events = array(); foreach(array_merge(get_not_workable($start),get_not_workable($end)) as $time){ if($time < $start || $time > $end) continue; $events[] = array( 'start' => date('Y-m-d\TH:i:s',$time), 'end' => date('Y-m-d\T23:59:59',$time), 'backgroundColor' => '#cecece', 'rendering' => 'background' ); $events[] = array( 'start' => date('Y-m-d',$time), 'end' => date('Y-m-d',$time), 'backgroundColor' => '#cecece', 'allDay' => true, 'rendering' => 'background' ); } if(isset($_['plannings']) && count($_['plannings'])!=0){ $myUser->preference('planning_selected_calendars',json_encode($_['plannings'])); $myUser->loadPreferences(); $_SESSION['currentUser'] = serialize($myUser); foreach(PlanningEvent::getAll($myUser->login,$myUser->ranks[$myFirm->id],$plannings,$start,$end) as $event){ if($event->startDate > $event->endDate) continue; $textColor = get_light($event->type->color) < 0.6 ? '#fefefefe': '#333333' ; $isAllDay = false; /*if($conf->get('planning_day_start')!='' && $conf->get('planning_day_end')!=''){ if(date('H:i:s',$event->startDate) == $conf->get('planning_day_start').':00' && date('H:i:s',$event->endDate) == $conf->get('planning_day_end').':00') $isAllDay = true; }*/ $events[] = array( 'id' => $event->id, 'title' => html_entity_decode($event->label,ENT_QUOTES,'UTF-8'), 'type' => $event->type->id, 'planning' => $event->planning->id, 'allDay' => $isAllDay, 'street' => $event->street, 'city' => $event->city, 'zip' => $event->zip, 'notificationNumber' => $event->notificationNumber, 'notificationUnity' => $event->notificationUnity, 'start' => date('Y-m-d\TH:i:s',$event->startDate), 'end' => date('Y-m-d\TH:i:s',$event->endDate), 'backgroundColor' => $event->type->color, 'underlineColor' => $event->planning->color, 'planningLabel' => $event->planning->label, 'borderColor' => 'transparent', 'editable' => $conf->get('planning_allow_event_edit') == true, 'icon' => $event->type->icon, 'textColor' => $textColor, 'description' => html_entity_decode(str_replace('\n',"\n",$event->description),ENT_QUOTES,'UTF-8'), 'location' => $event->street.' '.$event->zip.' '.$event->city, 'repeatOccurence' => $event->repeatOccurence, 'repeatUntil' => $event->repeatUntil, 'repeatYearlyMonth' => $event->repeatYearlyMonth, 'repeatYearlyNumber' => $event->repeatYearlyNumber, 'repeatMonthlyDay' => $event->repeatMonthlyDay, 'repeatMonthlyNumber'=> $event->repeatMonthlyNumber, 'repeatWeeklyDay' => explode(',',$event->repeatWeeklyDay), 'repeatDailyNumber' => $event->repeatDailyNumber, 'repeatType' => $event->repeatType ); } } $response = $events; }); break; //Ajout ou modification d'élément planningevent case 'planning_event_save': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','edit'); require_once(__DIR__.SLASH.'Planning.class.php'); require_once(__DIR__.SLASH.'PlanningShare.class.php'); require_once(__DIR__.SLASH.'PlanningEvent.class.php'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); $item = PlanningEvent::provide('id',1); if(!$item) throw new Exception("Cet événement n'existe plus, merci de rafraîchir votre planning."); $planning = $item->id==0 ? Planning::getById($_['planning']) : $item->join('planning'); if($planning->owner != $myUser->login){ if(PlanningShare::rowCount(array('planning'=>$planning->id,'recipient'=>$myUser->login,'edit'=>1))==0) throw new Exception("Vous n'avez pas la permission d'éditer cet évenement", 403); } $start = explode('/',$_['startDate']); $end = explode('/',$_['endDate']); $startDate = mktime($_['startHour'],$_['startMinut'],0,$start[1],$start[0],$start[2]); $endDate = mktime($_['endHour'],$_['endMinut'],0,$end[1],$end[0],$end[2]); if($startDate > $endDate) throw new Exception("Dates incohérentes"); $item->label = $_['label']; if(isset($_['planning']) && !empty($_['planning']) && $_['planning']!=0) $item->planning = $_['planning']; if(isset($_['type'])) $item->type = $_['type']; $item->startDate = $startDate; $item->endDate = $endDate; $item->description = $_['description']; $item->street = $_['street']; $item->city = $_['city']; $item->zip = $_['zip']; if(isset($_['event-repeat-type'])){ $item->repeatType = $_['event-repeat-type']; if($_['repeatEndType'] == 'occurence') $item->repeatOccurence = $_['event-repeat-occurences']; if($_['repeatEndType'] == 'until') $item->repeatUntil = $_['event-repeat-until']; $item->repeatYearlyMonth = $_['event-repeat-yearly-month']; $item->repeatYearlyNumber = $_['event-repeat-yearly-number']; $item->repeatMonthlyDay = $_['event-repeat-monthly-day']; $item->repeatMonthlyNumber = $_['event-repeat-monthly-number']; if(isset($_['weeklyDay']) && is_array($_['weeklyDay'])) $item->repeatWeeklyDay = implode(',',$_['weeklyDay']) ; $item->repeatDailyNumber = $_['event-repeat-daily-number']; } if(isset($_['notificationNumber']) && !empty($_['notificationNumber'])){ //Si les parametres de notifications ont changé on remet a zero l'etat de notification if($_['notificationNumber'] != $item->notificationNumber) $item->notificationState = ''; $item->notificationNumber = $_['notificationNumber']; } if(isset($_['notificationUnity'])) $item->notificationUnity = $_['notificationUnity']; $item->save(); }); break; //Suppression d'élement planningevent case 'planning_event_delete': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','delete'); require_once(__DIR__.SLASH.'PlanningEvent.class.php'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); $events = PlanningEvent::removeAll($myUser->login,$_['events']); }); break; /** EVENT TYPE **/ //Récuperation d'une liste de planningeventtype case 'planning_event_type_search': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','read'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); foreach(PlanningEventType::loadAll(array('state'=>PlanningEventType::ACTIVE),array('sort')) as $eventType){ $row = $eventType->toArray(); $row['textcolor'] = get_light($row['color'])> 0.5 ? '#333333':'#ffffff'; $row['editable'] = !empty($row['editable']); $row['superadmin'] = $myUser->superadmin || $row['editable']; $response['rows'][] = $row; } }); break; //Ajout ou modification d'élément planningeventtype case 'planning_event_type_save': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','configure'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); $item = PlanningEventType::provide(); if(!$item->editable && !$myUser->superadmin) throw new Exception("Item non éditable"); $item->label = $_['label']; $item->icon = $_['icon']; $item->editable = $_['editable']; if(isset($_['parent'])) $item->parent = $_['parent']; $item->color = $_['color']; $item->slug = slugify($_['label']); $item->save(); }); break; //Récuperation ou edition d'élément planningeventtype case 'planning_event_type_edit': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','configure'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); $response = PlanningEventType::getById($_['id']); }); break; case 'planning_event_type_sort': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','configure'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); foreach ($_['sort'] as $i=>$id) { PlanningEventType::change(array('sort'=>$i),array('id'=>$id)); } }); break; //Suppression d'élement planningeventtype case 'planning_event_type_delete': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','configure'); require_once(__DIR__.SLASH.'PlanningEventType.class.php'); $item = PlanningEventType::getById($_['id']); $item->state = PlanningEventType::INACTIVE; $item->save(); }); break; //Sauvegarde des configurations de planning case 'planning_setting_save': Action::write(function(&$response){ global $myUser,$_,$conf; User::check_access('planning','configure'); foreach(Configuration::setting('planning') as $key=>$value){ if(!is_array($value)) continue; $allowed[] = $key; } foreach ($_['fields'] as $key => $value) { if(in_array($key, $allowed)) $conf->put($key,$value); } }); break; /** PLANNINGSHARE **/ //Récuperation d'une liste de planningshare case 'planning_share_search': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','read'); require_once(__DIR__.SLASH.'PlanningShare.class.php'); $shares = PlanningShare::loadAll(array('planning'=>$_['planning'])); foreach($shares as $planningshare){ $row = $planningshare->toArray(); $row['edit'] = $row['edit']==0?null:$row['edit']; if($planningshare->recipientEntity=='rank'){ $rank = Rank::getById($planningshare->recipient); $row['recipient'] = $rank->label; $row['recipientType'] = "Rang"; }else{ $row['recipient'] = User::byLogin($planningshare->recipient)->fullName(); $row['recipientType'] = "Utilisateur"; } $response['rows'][] = $row; } }); break; //Ajout ou modification d'élément planningshare case 'planning_share_save': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','edit'); require_once(__DIR__.SLASH.'Planning.class.php'); require_once(__DIR__.SLASH.'PlanningShare.class.php'); if(empty($_['recipient'])) throw new Exception("Vous devez préciser le destinataire du partage"); //vérifie que ce destinataire n'a pas déja un partage sur ce planning if(PlanningShare::rowCount(array('planning'=>$_['planning'],'recipient'=>$_['recipient'])) >0) throw new Exception("Ce destinataire a déja un partage sur ce planning, veuillez supprimer l'ancien partage avant d'en créer un nouveau"); $planning = Planning::getById($_['planning']); if(!$planning) throw new Exception("Planning inexistant"); if($planning->owner != $myUser->login) throw new Exception("Vous n'êtes pas propriétaire du planning"); if(!$_['read'] && !$_['edit']) throw new Exception("Vous devez cocher au moins un droit de planning"); $item = PlanningShare::provide(); $item->planning = $planning->id; $item->recipient = stripslashes($_['recipient']); $item->recipientEntity = $_['recipientEntity']; $item->read = $_['read']; $item->edit = $_['edit']; $item->save(); }); break; //Suppression d'élement planningshare case 'planning_share_delete': Action::write(function(&$response){ global $myUser,$_; User::check_access('planning','delete'); require_once(__DIR__.SLASH.'Planning.class.php'); require_once(__DIR__.SLASH.'PlanningShare.class.php'); $item = PlanningShare::provide(); $planning = Planning::getById($item->planning); if($planning->owner != $myUser->login) throw new Exception("Vous n'êtes pas propriétaire du planning"); PlanningShare::deleteById($_['id']); }); break; } ?>