diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index fba2cf10cbc..3b539895348 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -77,9 +77,13 @@ $datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2mi
// Security check
$socid = GETPOST('socid', 'int');
$id = GETPOST('id', 'int');
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
-if ($user->socid && $socid) $result = restrictedArea($user, 'societe', $socid);
+if ($user->socid && $socid) {
+ $result = restrictedArea($user, 'societe', $socid);
+}
$error = GETPOST("error");
$donotclearsession = GETPOST('donotclearsession') ?GETPOST('donotclearsession') : 0;
@@ -114,11 +118,17 @@ $hookmanager->initHooks(array('actioncard', 'globalcard'));
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
$TRemindTypes = array();
-if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) $TRemindTypes['browser'] = array('label'=>$langs->trans('BrowserPush'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_BROWSER) ? 1 : 0));
-if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) $TRemindTypes['email'] = array('label'=>$langs->trans('EMail'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_EMAIL) ? 1 : 0));
+if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) {
+ $TRemindTypes['browser'] = array('label'=>$langs->trans('BrowserPush'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_BROWSER) ? 1 : 0));
+}
+if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) {
+ $TRemindTypes['email'] = array('label'=>$langs->trans('EMail'), 'disabled'=>(empty($conf->global->AGENDA_REMINDER_EMAIL) ? 1 : 0));
+}
$TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month'), 'w'=>$langs->trans('Weeks'), 'd'=>$langs->trans('Days'), 'h'=>$langs->trans('Hours'), 'i'=>$langs->trans('Minutes'));
@@ -129,60 +139,65 @@ $TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month')
$listUserAssignedUpdated = false;
// Remove user to assigned list
-if (empty($reshook) && (GETPOST('removedassigned') || GETPOST('removedassigned') == '0'))
-{
+if (empty($reshook) && (GETPOST('removedassigned') || GETPOST('removedassigned') == '0')) {
$idtoremove = GETPOST('removedassigned');
- if (!empty($_SESSION['assignedtouser'])) $tmpassigneduserids = json_decode($_SESSION['assignedtouser'], 1);
- else $tmpassigneduserids = array();
+ if (!empty($_SESSION['assignedtouser'])) {
+ $tmpassigneduserids = json_decode($_SESSION['assignedtouser'], 1);
+ } else {
+ $tmpassigneduserids = array();
+ }
- foreach ($tmpassigneduserids as $key => $val)
- {
- if ($val['id'] == $idtoremove || $val['id'] == -1) unset($tmpassigneduserids[$key]);
+ foreach ($tmpassigneduserids as $key => $val) {
+ if ($val['id'] == $idtoremove || $val['id'] == -1) {
+ unset($tmpassigneduserids[$key]);
+ }
}
$_SESSION['assignedtouser'] = json_encode($tmpassigneduserids);
$donotclearsession = 1;
- if ($action == 'add') $action = 'create';
- if ($action == 'update') $action = 'edit';
+ if ($action == 'add') {
+ $action = 'create';
+ }
+ if ($action == 'update') {
+ $action = 'edit';
+ }
$listUserAssignedUpdated = true;
}
// Add user to assigned list
-if (empty($reshook) && (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser')))
-{
+if (empty($reshook) && (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser'))) {
// Add a new user
- if (GETPOST('assignedtouser') > 0)
- {
+ if (GETPOST('assignedtouser') > 0) {
$assignedtouser = array();
- if (!empty($_SESSION['assignedtouser']))
- {
+ if (!empty($_SESSION['assignedtouser'])) {
$assignedtouser = json_decode($_SESSION['assignedtouser'], true);
}
$assignedtouser[GETPOST('assignedtouser')] = array('id'=>GETPOST('assignedtouser'), 'transparency'=>GETPOST('transparency'), 'mandatory'=>1);
$_SESSION['assignedtouser'] = json_encode($assignedtouser);
}
$donotclearsession = 1;
- if ($action == 'add') $action = 'create';
- if ($action == 'update') $action = 'edit';
+ if ($action == 'add') {
+ $action = 'create';
+ }
+ if ($action == 'update') {
+ $action = 'edit';
+ }
$listUserAssignedUpdated = true;
}
// Link to a project
if (empty($reshook) && $action == 'classin' && ($user->rights->agenda->allactions->create ||
- (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create)))
-{
+ (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create))) {
//$object->fetch($id);
$object->setProject(GETPOST('projectid', 'int'));
}
// Action clone object
-if (empty($reshook) && $action == 'confirm_clone' && $confirm == 'yes')
-{
- if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
- {
+if (empty($reshook) && $action == 'confirm_clone' && $confirm == 'yes') {
+ if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
} else {
if ($id > 0) {
@@ -204,23 +219,22 @@ if (empty($reshook) && $action == 'confirm_clone' && $confirm == 'yes')
}
// Add event
-if (empty($reshook) && $action == 'add')
-{
+if (empty($reshook) && $action == 'add') {
$error = 0;
- if (empty($backtopage))
- {
- if ($socid > 0) $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
- else $backtopage = DOL_URL_ROOT.'/comm/action/index.php';
+ if (empty($backtopage)) {
+ if ($socid > 0) {
+ $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
+ } else {
+ $backtopage = DOL_URL_ROOT.'/comm/action/index.php';
+ }
}
- if (!empty($socpeopleassigned[0]))
- {
+ if (!empty($socpeopleassigned[0])) {
$result = $contact->fetch($socpeopleassigned[0]);
}
- if ($cancel)
- {
+ if ($cancel) {
header("Location: ".$backtopage);
exit;
}
@@ -232,23 +246,20 @@ if (empty($reshook) && $action == 'add')
$datef = dol_mktime($fulldayevent ? '23' : GETPOST("p2hour", 'int'), $fulldayevent ? '59' : GETPOST("p2min", 'int'), $fulldayevent ? '59' : GETPOST("apsec", 'int'), GETPOST("p2month", 'int'), GETPOST("p2day", 'int'), GETPOST("p2year", 'int'), 'tzuser');
// Check parameters
- if (!$datef && $percentage == 100)
- {
+ if (!$datef && $percentage == 100) {
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
}
- if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && !GETPOST('label'))
- {
+ if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && !GETPOST('label')) {
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
}
// Initialisation objet cactioncomm
- if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) // actioncode is '0'
- {
+ if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) { // actioncode is '0'
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
@@ -256,8 +267,7 @@ if (empty($reshook) && $action == 'add')
$object->type_code = GETPOST('actioncode', 'aZ09');
}
- if (!$error)
- {
+ if (!$error) {
// Initialisation objet actioncomm
$object->priority = GETPOSTISSET("priority") ? GETPOST("priority", "int") : 0;
$object->fulldayevent = (!empty($fulldayevent) ? 1 : 0);
@@ -265,14 +275,11 @@ if (empty($reshook) && $action == 'add')
$object->label = GETPOST('label', 'alphanohtml');
$object->fk_element = GETPOST("fk_element", 'int');
$object->elementtype = GETPOST("elementtype", 'alpha');
- if (!GETPOST('label'))
- {
- if (GETPOST('actioncode', 'aZ09') == 'AC_RDV' && $contact->getFullName($langs))
- {
+ if (!GETPOST('label')) {
+ if (GETPOST('actioncode', 'aZ09') == 'AC_RDV' && $contact->getFullName($langs)) {
$object->label = $langs->transnoentitiesnoconv("TaskRDVWith", $contact->getFullName($langs));
} else {
- if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code)
- {
+ if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code) {
$object->label = $langs->transnoentitiesnoconv("Action".$object->type_code)."\n";
} else {
$cactioncomm->fetch($object->type_code);
@@ -301,13 +308,15 @@ if (empty($reshook) && $action == 'add')
$transparency = (GETPOST("transparency") == 'on' ? 1 : 0);
$listofuserid = array();
- if (!empty($_SESSION['assignedtouser'])) $listofuserid = json_decode($_SESSION['assignedtouser'], true);
+ if (!empty($_SESSION['assignedtouser'])) {
+ $listofuserid = json_decode($_SESSION['assignedtouser'], true);
+ }
$i = 0;
- foreach ($listofuserid as $key => $value)
- {
- if ($i == 0) // First entry
- {
- if ($value['id'] > 0) $object->userownerid = $value['id'];
+ foreach ($listofuserid as $key => $value) {
+ if ($i == 0) { // First entry
+ if ($value['id'] > 0) {
+ $object->userownerid = $value['id'];
+ }
$object->transparency = $transparency;
}
@@ -317,17 +326,19 @@ if (empty($reshook) && $action == 'add')
}
}
- if (!$error && !empty($conf->global->AGENDA_ENABLE_DONEBY))
- {
- if (GETPOST("doneby") > 0) $object->userdoneid = GETPOST("doneby", "int");
+ if (!$error && !empty($conf->global->AGENDA_ENABLE_DONEBY)) {
+ if (GETPOST("doneby") > 0) {
+ $object->userdoneid = GETPOST("doneby", "int");
+ }
}
$object->note_private = trim(GETPOST("note", "restricthtml"));
- if (GETPOSTISSET("contactid")) $object->contact = $contact;
+ if (GETPOSTISSET("contactid")) {
+ $object->contact = $contact;
+ }
- if (GETPOST('socid', 'int') > 0)
- {
+ if (GETPOST('socid', 'int') > 0) {
$object->socid = GETPOST('socid', 'int');
$object->fetch_thirdparty();
@@ -335,51 +346,45 @@ if (empty($reshook) && $action == 'add')
}
// Check parameters
- if (empty($object->userownerid) && empty($_SESSION['assignedtouser']))
- {
+ if (empty($object->userownerid) && empty($_SESSION['assignedtouser'])) {
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
}
- if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent))))
- {
+ if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent)))) {
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
}
- if (!GETPOST('apyear') && !GETPOST('adyear'))
- {
+ if (!GETPOST('apyear') && !GETPOST('adyear')) {
$error++; $donotclearsession = 1;
$action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
}
- foreach ($socpeopleassigned as $cid)
- {
+ foreach ($socpeopleassigned as $cid) {
$object->socpeopleassigned[$cid] = array('id' => $cid);
}
- if (!empty($object->socpeopleassigned))
- {
+ if (!empty($object->socpeopleassigned)) {
reset($object->socpeopleassigned);
$object->contact_id = key($object->socpeopleassigned);
}
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) $error++;
+ if ($ret < 0) {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
$db->begin();
// Creation of action/event
$idaction = $object->create($user);
- if ($idaction > 0)
- {
- if (!$object->error)
- {
+ if ($idaction > 0) {
+ if (!$object->error) {
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
@@ -387,7 +392,9 @@ if (empty($reshook) && $action == 'add')
unset($_SESSION['assignedtouser']);
$moreparam = '';
- if ($user->id != $object->userownerid) $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
+ if ($user->id != $object->userownerid) {
+ $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
+ }
// Create reminders
if ($addreminder == 'on') {
@@ -401,11 +408,12 @@ if (empty($reshook) && $action == 'add')
$actionCommReminder->offsetvalue = $offsetvalue;
$actionCommReminder->status = $actionCommReminder::STATUS_TODO;
$actionCommReminder->fk_actioncomm = $object->id;
- if ($remindertype == 'email') $actionCommReminder->fk_email_template = $modelmail;
+ if ($remindertype == 'email') {
+ $actionCommReminder->fk_email_template = $modelmail;
+ }
// the notification must be created for every user assigned to the event
- foreach ($object->userassigned as $userassigned)
- {
+ foreach ($object->userassigned as $userassigned) {
$actionCommReminder->fk_user = $userassigned['id'];
$res = $actionCommReminder->create($user);
@@ -427,12 +435,10 @@ if (empty($reshook) && $action == 'add')
$db->commit();
}
- if (!empty($backtopage))
- {
+ if (!empty($backtopage)) {
dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
header("Location: ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
- } elseif ($idaction)
- {
+ } elseif ($idaction) {
header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam ? '&'.$moreparam : ''));
} else {
header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam ? '?'.$moreparam : ''));
@@ -457,10 +463,8 @@ if (empty($reshook) && $action == 'add')
/*
* Action update event
*/
-if (empty($reshook) && $action == 'update')
-{
- if (empty($cancel))
- {
+if (empty($reshook) && $action == 'update') {
+ if (empty($cancel)) {
$fulldayevent = GETPOST('fullday');
$aphour = GETPOST('aphour', 'int');
$apmin = GETPOST('apmin', 'int');
@@ -469,10 +473,18 @@ if (empty($reshook) && $action == 'update')
$percentage = in_array(GETPOST('status'), array(-1, 100)) ?GETPOST('status') : (in_array(GETPOST('complete'), array(-1, 100)) ?GETPOST('complete') : GETPOST("percentage")); // If status is -1 or 100, percentage is not defined and we must use status
// Clean parameters
- if ($aphour == -1) $aphour = '0';
- if ($apmin == -1) $apmin = '0';
- if ($p2hour == -1) $p2hour = '0';
- if ($p2min == -1) $p2min = '0';
+ if ($aphour == -1) {
+ $aphour = '0';
+ }
+ if ($apmin == -1) {
+ $apmin = '0';
+ }
+ if ($p2hour == -1) {
+ $p2hour = '0';
+ }
+ if ($p2min == -1) {
+ $p2min = '0';
+ }
$object->fetch($id);
$object->fetch_optionals();
@@ -493,7 +505,9 @@ if (empty($reshook) && $action == 'update')
$object->socid = GETPOST("socid", "int");
$socpeopleassigned = GETPOST("socpeopleassigned", 'array');
$object->socpeopleassigned = array();
- foreach ($socpeopleassigned as $cid) $object->socpeopleassigned[$cid] = array('id' => $cid);
+ foreach ($socpeopleassigned as $cid) {
+ $object->socpeopleassigned[$cid] = array('id' => $cid);
+ }
$object->contact_id = GETPOST("contactid", 'int');
if (empty($object->contact_id) && !empty($object->socpeopleassigned)) {
reset($object->socpeopleassigned);
@@ -503,8 +517,7 @@ if (empty($reshook) && $action == 'update')
$object->note_private = trim(GETPOST("note", "restricthtml"));
$object->fk_element = GETPOST("fk_element", "int");
$object->elementtype = GETPOST("elementtype", "alphanohtml");
- if (!$datef && $percentage == 100)
- {
+ if (!$datef && $percentage == 100) {
$error++; $donotclearsession = 1;
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), $object->errors, 'errors');
$action = 'edit';
@@ -514,23 +527,26 @@ if (empty($reshook) && $action == 'update')
// Users
$listofuserid = array();
- if (!empty($_SESSION['assignedtouser'])) // Now concat assigned users
- {
+ if (!empty($_SESSION['assignedtouser'])) { // Now concat assigned users
// Restore array with key with same value than param 'id'
$tmplist1 = json_decode($_SESSION['assignedtouser'], true);
- foreach ($tmplist1 as $key => $val)
- {
- if ($val['id'] > 0 && $val['id'] != $assignedtouser) $listofuserid[$val['id']] = $val;
+ foreach ($tmplist1 as $key => $val) {
+ if ($val['id'] > 0 && $val['id'] != $assignedtouser) {
+ $listofuserid[$val['id']] = $val;
+ }
}
} else {
$assignedtouser = (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0);
- if ($assignedtouser) $listofuserid[$assignedtouser] = array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>($user->id == $assignedtouser ? $transparency : '')); // Owner first
+ if ($assignedtouser) {
+ $listofuserid[$assignedtouser] = array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>($user->id == $assignedtouser ? $transparency : '')); // Owner first
+ }
}
$object->userassigned = array(); $object->userownerid = 0; // Clear old content
$i = 0;
- foreach ($listofuserid as $key => $val)
- {
- if ($i == 0) $object->userownerid = $val['id'];
+ foreach ($listofuserid as $key => $val) {
+ if ($i == 0) {
+ $object->userownerid = $val['id'];
+ }
$object->userassigned[$val['id']] = array('id'=>$val['id'], 'mandatory'=>0, 'transparency'=>($user->id == $val['id'] ? $transparency : ''));
$i++;
}
@@ -538,22 +554,21 @@ if (empty($reshook) && $action == 'update')
$object->transparency = $transparency; // We set transparency on event (even if we can also store it on each user, standard says this property is for event)
// TODO store also transparency on owner user
- if (!empty($conf->global->AGENDA_ENABLE_DONEBY))
- {
- if (GETPOST("doneby")) $object->userdoneid = GETPOST("doneby", "int");
+ if (!empty($conf->global->AGENDA_ENABLE_DONEBY)) {
+ if (GETPOST("doneby")) {
+ $object->userdoneid = GETPOST("doneby", "int");
+ }
}
// Check parameters
- if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) // actioncode is '0'
- {
+ if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) { // actioncode is '0'
$error++; $donotclearsession = 1;
$action = 'edit';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
} else {
$result = $cactioncomm->fetch(GETPOST('actioncode', 'aZ09'));
}
- if (empty($object->userownerid))
- {
+ if (empty($object->userownerid)) {
$error++; $donotclearsession = 1;
$action = 'edit';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
@@ -561,7 +576,9 @@ if (empty($reshook) && $action == 'update')
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) $error++;
+ if ($ret < 0) {
+ $error++;
+ }
if (!$error) {
// check if an event resource is already in use
@@ -622,23 +639,19 @@ if (empty($reshook) && $action == 'update')
}
}
- if (!$error)
- {
+ if (!$error) {
$db->begin();
$result = $object->update($user);
- if ($result > 0)
- {
+ if ($result > 0) {
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
$object->loadReminders();
- if (!empty($object->reminders) && $object->datep > dol_now())
- {
- foreach ($object->reminders as $reminder)
- {
+ if (!empty($object->reminders) && $object->datep > dol_now()) {
+ foreach ($object->reminders as $reminder) {
$reminder->delete($user);
}
$object->reminders = array();
@@ -656,11 +669,12 @@ if (empty($reshook) && $action == 'update')
$actionCommReminder->offsetvalue = $offsetvalue;
$actionCommReminder->status = $actionCommReminder::STATUS_TODO;
$actionCommReminder->fk_actioncomm = $object->id;
- if ($remindertype == 'email') $actionCommReminder->fk_email_template = $modelmail;
+ if ($remindertype == 'email') {
+ $actionCommReminder->fk_email_template = $modelmail;
+ }
// the notification must be created for every user assigned to the event
- foreach ($object->userassigned as $userassigned)
- {
+ foreach ($object->userassigned as $userassigned) {
$actionCommReminder->fk_user = $userassigned['id'];
$res = $actionCommReminder->create($user);
@@ -677,8 +691,11 @@ if (empty($reshook) && $action == 'update')
unset($_SESSION['assignedtouser']);
- if (!$error) $db->commit();
- else $db->rollback();
+ if (!$error) {
+ $db->commit();
+ } else {
+ $db->rollback();
+ }
} else {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
@@ -686,10 +703,8 @@ if (empty($reshook) && $action == 'update')
}
}
- if (!$error)
- {
- if (!empty($backtopage))
- {
+ if (!$error) {
+ if (!empty($backtopage)) {
unset($_SESSION['assignedtouser']);
header("Location: ".$backtopage);
exit;
@@ -700,20 +715,17 @@ if (empty($reshook) && $action == 'update')
/*
* delete event
*/
-if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes')
-{
+if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
$object->fetch($id);
$object->fetch_optionals();
$object->fetch_userassigned();
$object->oldcopy = clone $object;
if ($user->rights->agenda->myactions->delete
- || $user->rights->agenda->allactions->delete)
- {
+ || $user->rights->agenda->allactions->delete) {
$result = $object->delete();
- if ($result >= 0)
- {
+ if ($result >= 0) {
header("Location: index.php");
exit;
} else {
@@ -726,16 +738,14 @@ if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes
* Action move update, used when user move an event in calendar by drag'n drop
* TODO Move this into page comm/action/index that trigger this call by the drag and drop of event.
*/
-if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
-{
+if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate') {
$error = 0;
$shour = dol_print_date($object->datep, "%H", 'tzuserrel'); // We take the date visible by user $newdate is also date visible by user.
$smin = dol_print_date($object->datep, "%M", 'tzuserrel');
$newdate = GETPOST('newdate', 'alpha');
- if (empty($newdate) || strpos($newdate, 'dayevent_') != 0)
- {
+ if (empty($newdate) || strpos($newdate, 'dayevent_') != 0) {
header("Location: ".$backtopage);
exit;
}
@@ -743,10 +753,8 @@ if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
$datep = dol_mktime($shour, $smin, 0, substr($newdate, 13, 2), substr($newdate, 15, 2), substr($newdate, 9, 4), 'tzuserrel');
//print dol_print_date($datep, 'dayhour');exit;
- if ($datep != $object->datep)
- {
- if (!empty($object->datef))
- {
+ if ($datep != $object->datep) {
+ if (!empty($object->datef)) {
$object->datef += $datep - $object->datep;
}
$object->datep = $datep;
@@ -822,8 +830,7 @@ if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
}
}
}
- if (!empty($backtopage))
- {
+ if (!empty($backtopage)) {
header("Location: ".$backtopage);
exit;
} else {
@@ -857,21 +864,20 @@ $arrayrecurrulefreq = array(
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
llxHeader('', $langs->trans("Agenda"), $help_url);
-if ($action == 'create')
-{
+if ($action == 'create') {
$contact = new Contact($db);
$socpeopleassigned = GETPOST("socpeopleassigned", 'array');
- if (!empty($socpeopleassigned[0]))
- {
+ if (!empty($socpeopleassigned[0])) {
$result = $contact->fetch($socpeopleassigned[0]);
- if ($result < 0) dol_print_error($db, $contact->error);
+ if ($result < 0) {
+ dol_print_error($db, $contact->error);
+ }
}
dol_set_focus("#label");
- if (!empty($conf->use_javascript_ajax))
- {
+ if (!empty($conf->use_javascript_ajax)) {
print "\n".''."\n";
- foreach ($showextcals as $val)
- {
+ foreach ($showextcals as $val) {
$htmlname = md5($val['name']);
$s .= '
'.$val['name'].'
';
}
@@ -538,11 +574,9 @@ if (!empty($conf->use_javascript_ajax)) // If javascript on
// Calendars from hooks
$parameters = array(); $object = null;
$reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
- if (empty($reshook))
- {
+ if (empty($reshook)) {
$s .= $hookmanager->resPrint;
- } elseif ($reshook > 1)
- {
+ } elseif ($reshook > 1) {
$s = $hookmanager->resPrint;
}
@@ -551,12 +585,17 @@ if (!empty($conf->use_javascript_ajax)) // If javascript on
{
$newparam = $param; // newparam is for birthday links
$newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
- if (!preg_match('/showbirthday=/i', $newparam)) $newparam .= '&showbirthday=1';
+ if (!preg_match('/showbirthday=/i', $newparam)) {
+ $newparam .= '&showbirthday=1';
+ }
$link = '';
- if (empty($showbirthday)) $link .= $langs->trans("AgendaShowBirthdayEvents");
- else $link .= $langs->trans("AgendaHideBirthdayEvents");
+ if (empty($showbirthday)) {
+ $link .= $langs->trans("AgendaShowBirthdayEvents");
+ } else {
+ $link .= $langs->trans("AgendaHideBirthdayEvents");
+ }
$link .= ' ';
}
@@ -567,7 +606,9 @@ $eventarray = array();
// DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
$sql = 'SELECT ';
-if ($usergroup > 0) $sql .= " DISTINCT";
+if ($usergroup > 0) {
+ $sql .= " DISTINCT";
+}
$sql .= ' a.id, a.label,';
$sql .= ' a.datep,';
$sql .= ' a.datep2,';
@@ -578,31 +619,44 @@ $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
$sql .= ' a.fk_element, a.elementtype,';
$sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
$sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
-if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
+}
// We must filter on resource table
-if ($resourceid > 0) $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
+if ($resourceid > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0) $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
-if ($usergroup > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
+if ($filtert > 0 || $usergroup > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
+}
+if ($usergroup > 0) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
+}
$sql .= ' WHERE a.fk_action = ca.id';
$sql .= ' AND a.entity IN ('.getEntity('agenda').')';
// Condition on actioncode
-if (!empty($actioncode))
-{
- if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
- {
- if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'";
- elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'";
- else {
- if ($actioncode == 'AC_OTH') $sql .= " AND ca.type != 'systemauto'";
- if ($actioncode == 'AC_OTH_AUTO') $sql .= " AND ca.type = 'systemauto'";
+if (!empty($actioncode)) {
+ if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
+ if ($actioncode == 'AC_NON_AUTO') {
+ $sql .= " AND ca.type != 'systemauto'";
+ } elseif ($actioncode == 'AC_ALL_AUTO') {
+ $sql .= " AND ca.type = 'systemauto'";
+ } else {
+ if ($actioncode == 'AC_OTH') {
+ $sql .= " AND ca.type != 'systemauto'";
+ }
+ if ($actioncode == 'AC_OTH_AUTO') {
+ $sql .= " AND ca.type = 'systemauto'";
+ }
}
} else {
- if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'";
- elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'";
- else {
- if (is_array($actioncode))
- {
+ if ($actioncode == 'AC_NON_AUTO') {
+ $sql .= " AND ca.type != 'systemauto'";
+ } elseif ($actioncode == 'AC_ALL_AUTO') {
+ $sql .= " AND ca.type = 'systemauto'";
+ } else {
+ if (is_array($actioncode)) {
$sql .= " AND ca.code IN ('".implode("','", $actioncode)."')";
} else {
$sql .= " AND ca.code IN ('".implode("','", explode(',', $actioncode))."')";
@@ -610,15 +664,24 @@ if (!empty($actioncode))
}
}
}
-if ($resourceid > 0) $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
-if ($pid) $sql .= " AND a.fk_project=".$db->escape($pid);
-if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")";
-if ($socid > 0) $sql .= ' AND a.fk_soc = '.$socid;
+if ($resourceid > 0) {
+ $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
+}
+if ($pid) {
+ $sql .= " AND a.fk_project=".$db->escape($pid);
+}
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")";
+}
+if ($socid > 0) {
+ $sql .= ' AND a.fk_soc = '.$socid;
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
+if ($filtert > 0 || $usergroup > 0) {
+ $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
+}
//var_dump($day.' '.$month.' '.$year);
-if ($action == 'show_day')
-{
+if ($action == 'show_day') {
$sql .= " AND (";
$sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
$sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
@@ -642,18 +705,33 @@ if ($action == 'show_day')
$sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
$sql .= ')';
}
-if ($type) $sql .= " AND ca.id = ".$type;
-if ($status == '0') { $sql .= " AND a.percent = 0"; }
-if ($status == '-1') { $sql .= " AND a.percent = -1"; } // Not applicable
-if ($status == '50') { $sql .= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
-if ($status == 'done' || $status == '100') { $sql .= " AND (a.percent = 100)"; }
-if ($status == 'todo') { $sql .= " AND (a.percent >= 0 AND a.percent < 100)"; }
+if ($type) {
+ $sql .= " AND ca.id = ".$type;
+}
+if ($status == '0') {
+ $sql .= " AND a.percent = 0";
+}
+if ($status == '-1') {
+ $sql .= " AND a.percent = -1";
+} // Not applicable
+if ($status == '50') {
+ $sql .= " AND (a.percent > 0 AND a.percent < 100)";
+} // Running already started
+if ($status == 'done' || $status == '100') {
+ $sql .= " AND (a.percent = 100)";
+}
+if ($status == 'todo') {
+ $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0)
-{
+if ($filtert > 0 || $usergroup > 0) {
$sql .= " AND (";
- if ($filtert > 0) $sql .= "ar.fk_element = ".$filtert;
- if ($usergroup > 0) $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup;
+ if ($filtert > 0) {
+ $sql .= "ar.fk_element = ".$filtert;
+ }
+ if ($usergroup > 0) {
+ $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup;
+ }
$sql .= ")";
}
// Sort on date
@@ -663,19 +741,16 @@ $sql .= ' ORDER BY datep';
dol_syslog("comm/action/index.php", LOG_DEBUG);
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num = $db->num_rows($resql);
$MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
$i = 0;
- while ($i < $num && $i < $MAXONSAMEPAGE)
- {
+ while ($i < $num && $i < $MAXONSAMEPAGE) {
$obj = $db->fetch_object($resql);
// Discard auto action if option is on
- if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO')
- {
+ if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
$i++;
continue;
}
@@ -720,11 +795,13 @@ if ($resql)
// Defined date_start_in_calendar and date_end_in_calendar property
// They are date start and end of action but modified to not be outside calendar view.
$event->date_start_in_calendar = $event->datep;
- if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar = $event->datef;
- else $event->date_end_in_calendar = $event->datep;
+ if ($event->datef != '' && $event->datef >= $event->datep) {
+ $event->date_end_in_calendar = $event->datef;
+ } else {
+ $event->date_end_in_calendar = $event->datep;
+ }
// Define ponctual property
- if ($event->date_start_in_calendar == $event->date_end_in_calendar)
- {
+ if ($event->date_start_in_calendar == $event->date_end_in_calendar) {
$event->ponctuel = 1;
}
@@ -732,8 +809,12 @@ if ($resql)
if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
// This record is out of visible range
} else {
- if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar = $firstdaytoshow;
- if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar = ($lastdaytoshow - 1);
+ if ($event->date_start_in_calendar < $firstdaytoshow) {
+ $event->date_start_in_calendar = $firstdaytoshow;
+ }
+ if ($event->date_end_in_calendar >= $lastdaytoshow) {
+ $event->date_end_in_calendar = ($lastdaytoshow - 1);
+ }
// Add an entry in actionarray for each day
$daycursor = $event->date_start_in_calendar;
@@ -753,7 +834,9 @@ if ($resql)
$j++;
$daykey += 60 * 60 * 24;
- if ($daykey > $event->date_end_in_calendar) $loop = false;
+ if ($daykey > $event->date_end_in_calendar) {
+ $loop = false;
+ }
} while ($loop);
//print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
@@ -767,15 +850,13 @@ if ($resql)
// BIRTHDATES CALENDAR
// Complete $eventarray with birthdates
-if ($showbirthday)
-{
+if ($showbirthday) {
// Add events in array
$sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
$sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
$sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
$sql .= " AND sp.entity IN (".getEntity('socpeople').")";
- if ($action == 'show_day')
- {
+ if ($action == 'show_day') {
$sql .= ' AND MONTH(birthday) = '.$month;
$sql .= ' AND DAY(birthday) = '.$day;
} else {
@@ -785,12 +866,10 @@ if ($showbirthday)
dol_syslog("comm/action/index.php", LOG_DEBUG);
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$event = new ActionComm($db);
@@ -859,13 +938,11 @@ if ($action == 'show_day') {
}
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$event = new ActionComm($db);
@@ -885,21 +962,17 @@ if ($resql)
$event->date_start_in_calendar = $event->datep;
$event->date_end_in_calendar = $event->datef;
- if ($obj->status == 3)
- {
+ if ($obj->status == 3) {
// Show no symbol for leave with state "leave approved"
$event->percentage = -1;
- } elseif ($obj->status == 2)
- {
+ } elseif ($obj->status == 2) {
// Show TO-DO symbol for leave with state "leave wait for approval"
$event->percentage = 0;
}
- if ($obj->halfday == 1)
- {
+ if ($obj->halfday == 1) {
$event->label = $obj->lastname.' ('.$langs->trans("Morning").')';
- } elseif ($obj->halfday == -1)
- {
+ } elseif ($obj->halfday == -1) {
$event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')';
} else {
$event->label = $obj->lastname;
@@ -923,11 +996,9 @@ if ($resql)
// EXTERNAL CALENDAR
// Complete $eventarray with external import Ical
-if (count($listofextcals))
-{
+if (count($listofextcals)) {
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
- foreach ($listofextcals as $extcal)
- {
+ foreach ($listofextcals as $extcal) {
$url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
$namecal = $extcal['name'];
$offsettz = $extcal['offsettz'];
@@ -940,29 +1011,27 @@ if (count($listofextcals))
// After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
//var_dump($ical->cal); exit;
$icalevents = array();
- if (is_array($ical->get_event_list())) $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
- if (is_array($ical->get_freebusy_list())) $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
+ if (is_array($ical->get_event_list())) {
+ $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
+ }
+ if (is_array($ical->get_freebusy_list())) {
+ $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
+ }
- if (count($icalevents) > 0)
- {
+ if (count($icalevents) > 0) {
// Duplicate all repeatable events into new entries
$moreicalevents = array();
- foreach ($icalevents as $icalevent)
- {
- if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
- {
+ foreach ($icalevents as $icalevent) {
+ if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
//if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
//if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
- if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
- {
+ if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
$datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
$datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
- } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime']))
- {
+ } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
$datecurstart = $icalevent['DTSTART']['unixtime'];
$datecurend = $icalevent['DTEND']['unixtime'];
- if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
- {
+ if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
//var_dump($ical->cal);
$tmpcurstart = $datecurstart;
$tmpcurend = $datecurend;
@@ -970,10 +1039,16 @@ if (count($listofextcals))
$tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
//var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
// Edit datecurstart and datecurend
- if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
- else $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
- if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
- else $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
+ if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
+ $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
+ } else {
+ $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
+ }
+ if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
+ $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
+ } else {
+ $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
+ }
}
// datecurstart and datecurend are now GMT date
//var_dump($datecurstart); var_dump($datecurend); exit;
@@ -987,18 +1062,19 @@ if (count($listofextcals))
$interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
$until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
$maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
- if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
- if ($datecurstart >= $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
+ if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
+ continue; // We discard repeatable event that end before start date to show
+ }
+ if ($datecurstart >= $lastdaytoshow) {
+ continue; // We discard repeatable event that start after end date to show
+ }
$numofevent = 0;
- while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
- {
- if ($datecurend >= $firstdaytoshow) // We add event
- {
+ while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
+ if ($datecurend >= $firstdaytoshow) { // We add event
$newevent = $icalevent;
unset($newevent['RRULE']);
- if ($icalevent['DTSTART;VALUE=DATE'])
- {
+ if ($icalevent['DTSTART;VALUE=DATE']) {
$newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
$newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
} else {
@@ -1010,27 +1086,22 @@ if (count($listofextcals))
// Jump on next occurence
$numofevent++;
$savdatecurstart = $datecurstart;
- if ($icalevent['RRULE']['FREQ'] == 'DAILY')
- {
+ if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
$datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
$datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
}
- if ($icalevent['RRULE']['FREQ'] == 'WEEKLY')
- {
+ if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
$datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
$datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
- } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY')
- {
+ } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
$datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
$datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
- } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY')
- {
+ } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
$datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
$datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
}
// Test to avoid infinite loop ($datecurstart must increase)
- if ($savdatecurstart >= $datecurstart)
- {
+ if ($savdatecurstart >= $datecurstart) {
dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
$datecurstart += 3600 * 24 * 7;
$datecurend += 3600 * 24 * 7;
@@ -1041,18 +1112,18 @@ if (count($listofextcals))
$icalevents = array_merge($icalevents, $moreicalevents);
// Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
- foreach ($icalevents as $icalevent)
- {
+ foreach ($icalevents as $icalevent) {
//var_dump($icalevent);
//print $icalevent['SUMMARY'].'->'.var_dump($icalevent).' ';exit;
- if (!empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
+ if (!empty($icalevent['RRULE'])) {
+ continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
+ }
// Create a new object action
$event = new ActionComm($db);
$addevent = false;
- if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
- {
+ if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
// For full day events, date are also GMT but they wont but converted using tz during output
$datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
$dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
@@ -1060,8 +1131,7 @@ if (count($listofextcals))
//print dol_print_date($dateend,'dayhour','gmt');
$event->fulldayevent = 1;
$addevent = true;
- } elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
- {
+ } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
$datestart = $icalevent['DTSTART'];
$dateend = $icalevent['DTEND'];
@@ -1071,8 +1141,7 @@ if (count($listofextcals))
$addevent = true;
//var_dump($offsettz);
//var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
- } elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind)
- {
+ } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
$datestart = $icalevent['DTSTART']['unixtime'];
$dateend = $icalevent['DTEND']['unixtime'];
@@ -1080,13 +1149,11 @@ if (count($listofextcals))
$dateend += +($offsettz * 3600);
// $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
- if ($buggedfile === 'uselocalandtznodaylight') // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
- {
+ if ($buggedfile === 'uselocalandtznodaylight') { // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
// TODO
}
// $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
- if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
- {
+ if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
$localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
$localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
$localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
@@ -1100,13 +1167,11 @@ if (count($listofextcals))
$addevent = true;
}
- if ($addevent)
- {
+ if ($addevent) {
$event->id = $icalevent['UID'];
$event->ref = $event->id;
$userId = $userstatic->findUserIdByEmail($namecal);
- if (!empty($userId) && $userId > 0)
- {
+ if (!empty($userId) && $userId > 0) {
$event->userassigned[$userId] = $userId;
$event->percentage = -1;
}
@@ -1123,21 +1188,30 @@ if (count($listofextcals))
$event->datep = $datestart + $usertime;
$event->datef = $dateend + $usertime;
- if ($icalevent['SUMMARY']) $event->label = $icalevent['SUMMARY'];
- elseif ($icalevent['DESCRIPTION']) $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
- else $event->label = $langs->trans("ExtSiteNoLabel");
+ if ($icalevent['SUMMARY']) {
+ $event->label = $icalevent['SUMMARY'];
+ } elseif ($icalevent['DESCRIPTION']) {
+ $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
+ } else {
+ $event->label = $langs->trans("ExtSiteNoLabel");
+ }
// Priority (see https://www.kanzaki.com/docs/ical/priority.html)
// LOW = 0 to 4
// MEDIUM = 5
// HIGH = 6 to 9
- if ($icalevent['PRIORITY']) $event->priority = $icalevent['PRIORITY'];
+ if ($icalevent['PRIORITY']) {
+ $event->priority = $icalevent['PRIORITY'];
+ }
// Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
- if ($icalevent['TRANSP'])
- {
- if ($icalevent['TRANSP'] == "TRANSPARENT") $event->transparency = 0; // 0 = available / free
- if ($icalevent['TRANSP'] == "OPAQUE") $event->transparency = 1; // 1 = busy
+ if ($icalevent['TRANSP']) {
+ if ($icalevent['TRANSP'] == "TRANSPARENT") {
+ $event->transparency = 0; // 0 = available / free
+ }
+ if ($icalevent['TRANSP'] == "OPAQUE") {
+ $event->transparency = 1; // 1 = busy
+ }
// TODO: MS outlook states
// X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
@@ -1147,30 +1221,37 @@ if (count($listofextcals))
// X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
}
- if ($icalevent['LOCATION']) $event->location = $icalevent['LOCATION'];
+ if ($icalevent['LOCATION']) {
+ $event->location = $icalevent['LOCATION'];
+ }
$event->date_start_in_calendar = $event->datep;
- if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar = $event->datef;
- else $event->date_end_in_calendar = $event->datep;
+ if ($event->datef != '' && $event->datef >= $event->datep) {
+ $event->date_end_in_calendar = $event->datef;
+ } else {
+ $event->date_end_in_calendar = $event->datep;
+ }
// Define ponctual property
- if ($event->date_start_in_calendar == $event->date_end_in_calendar)
- {
+ if ($event->date_start_in_calendar == $event->date_end_in_calendar) {
$event->ponctuel = 1;
//print 'x'.$datestart.'-'.$dateend;exit;
}
// Add event into $eventarray if date range are ok.
- if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow)
- {
+ if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
// This record is out of visible range
} else {
- if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar = $firstdaytoshow;
- if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar = ($lastdaytoshow - 1);
+ if ($event->date_start_in_calendar < $firstdaytoshow) {
+ $event->date_start_in_calendar = $firstdaytoshow;
+ }
+ if ($event->date_end_in_calendar >= $lastdaytoshow) {
+ $event->date_end_in_calendar = ($lastdaytoshow - 1);
+ }
// Add an entry in actionarray for each day
$daycursor = $event->date_start_in_calendar;
@@ -1187,7 +1268,9 @@ if (count($listofextcals))
//if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
$eventarray[$daykey][] = $event;
$daykey += 60 * 60 * 24; $daykeygmt += 60 * 60 * 24; // Add one day
- if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop = false;
+ if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
+ $loop = false;
+ }
} while ($loop);
}
}
@@ -1211,8 +1294,7 @@ if (!empty($hookmanager->resArray['eventarray'])) {
}
// Sort events
-foreach ($eventarray as $keyDate => &$dateeventarray)
-{
+foreach ($eventarray as $keyDate => &$dateeventarray) {
usort($dateeventarray, 'sort_events_by_date');
}
@@ -1224,11 +1306,12 @@ $cacheusers = array();
// Define theme_datacolor array
$color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
-if (is_readable($color_file))
-{
+if (is_readable($color_file)) {
include_once $color_file;
}
-if (!is_array($theme_datacolor)) $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
+if (!is_array($theme_datacolor)) {
+ $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
+}
$massactionbutton ='';
@@ -1238,8 +1321,7 @@ print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param,
print $s;
-if (empty($action) || $action == 'show_month') // View by month
-{
+if (empty($action) || $action == 'show_month') { // View by month
$newparam = $param; // newparam is for birthday links
$newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
$newparam = preg_replace('/action=show_month&?/i', '', $newparam);
@@ -1261,15 +1343,15 @@ if (empty($action) || $action == 'show_month') // View by month
// Column title of weeks numbers
echo ' # ';
$i = 0;
- while ($i < 7)
- {
+ while ($i < 7) {
print ' ';
$numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
- if (!empty($conf->dol_optimize_smallscreen))
- {
+ if (!empty($conf->dol_optimize_smallscreen)) {
$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
print $langs->trans($labelshort[$numdayinweek]);
- } else print $langs->trans("Day".$numdayinweek);
+ } else {
+ print $langs->trans("Day".$numdayinweek);
+ }
print ' '."\n";
$i++;
}
@@ -1283,15 +1365,11 @@ if (empty($action) || $action == 'show_month') // View by month
for ($iter_week = 0; $iter_week < 6; $iter_week++) {
echo " \n";
// Get date of the current day, format 'yyyy-mm-dd'
- if ($tmpday <= 0) // If number of the current day is in previous month
- {
+ if ($tmpday <= 0) { // If number of the current day is in previous month
$currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
- }
- elseif ($tmpday <= $max_day_in_month) // If number of the current day is in current month
- {
+ } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
$currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
- }
- else // If number of the current day is in next month
+ } else // If number of the current day is in next month
{
$currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
}
@@ -1304,7 +1382,9 @@ if (empty($action) || $action == 'show_month') // View by month
if ($tmpday <= 0) {
/* Show days before the beginning of the current month (previous month) */
$style = 'cal_other_month cal_past';
- if ($iter_day == 6) $style .= ' cal_other_month_right';
+ if ($iter_day == 6) {
+ $style .= ' cal_other_month_right';
+ }
echo ' ';
show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
echo " \n";
@@ -1312,11 +1392,19 @@ if (empty($action) || $action == 'show_month') // View by month
/* Show days of the current month */
$curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
$style = 'cal_current_month';
- if ($iter_day == 6) $style .= ' cal_current_month_right';
+ if ($iter_day == 6) {
+ $style .= ' cal_current_month_right';
+ }
$today = 0;
- if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) $today = 1;
- if ($today) $style = 'cal_today';
- if ($curtime < $todaytms) $style .= ' cal_past';
+ if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
+ $today = 1;
+ }
+ if ($today) {
+ $style = 'cal_today';
+ }
+ if ($curtime < $todaytms) {
+ $style .= ' cal_past';
+ }
//var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
echo ' ';
show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
@@ -1324,7 +1412,9 @@ if (empty($action) || $action == 'show_month') // View by month
} else {
/* Show days after the current month (next month) */
$style = 'cal_other_month';
- if ($iter_day == 6) $style .= ' cal_other_month_right';
+ if ($iter_day == 6) {
+ $style .= ' cal_other_month_right';
+ }
echo ' ';
show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
echo " \n";
@@ -1376,12 +1466,18 @@ if (empty($action) || $action == 'show_month') // View by month
$tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
$style = 'cal_current_month';
- if ($iter_day == 6) $style .= ' cal_other_month_right';
+ if ($iter_day == 6) {
+ $style .= ' cal_other_month_right';
+ }
$today = 0;
$todayarray = dol_getdate($now, 'fast');
- if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) $today = 1;
- if ($today) $style = 'cal_today';
+ if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
+ $today = 1;
+ }
+ if ($today) {
+ $style = 'cal_today';
+ }
echo ' ';
show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
@@ -1406,7 +1502,9 @@ if (empty($action) || $action == 'show_month') // View by month
$style = 'cal_current_month cal_current_month_oneday';
$today = 0;
$todayarray = dol_getdate($now, 'fast');
- if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) $today = 1;
+ if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
+ $today = 1;
+ }
//if ($today) $style='cal_today';
$timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
@@ -1424,12 +1522,12 @@ if (empty($action) || $action == 'show_month') // View by month
echo " \n";
/*
- echo ' ';
- echo '
';
- echo '
';
- echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
- echo '
'."\n";
- echo "
\n";
+ echo ' ';
+ echo '
';
+ echo '
';
+ echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
+ echo '
'."\n";
+ echo "
\n";
*/
echo '';
@@ -1437,8 +1535,7 @@ if (empty($action) || $action == 'show_month') // View by month
/* WIP View per hour */
$useviewhour = 0;
- if ($useviewhour)
- {
+ if ($useviewhour) {
print ''; // You can use div-table-responsive-no-min if you dont need reserved height for your table
$maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
@@ -1451,14 +1548,19 @@ if (empty($action) || $action == 'show_month') // View by month
$tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
$minhour = round($tmp[0], 0);
$maxhour = round($tmp[1], 0);
- if ($minhour > 23) $minhour = 23;
- if ($maxhour < 1) $maxhour = 1;
- if ($maxhour <= $minhour) { $maxhour = $minhour + 1; }
+ if ($minhour > 23) {
+ $minhour = 23;
+ }
+ if ($maxhour < 1) {
+ $maxhour = 1;
+ }
+ if ($maxhour <= $minhour) {
+ $maxhour = $minhour + 1;
+ }
$i = 0;
$j = 0;
- while ($i < 24)
- {
+ while ($i < 24) {
echo '
'."\n";
echo '
'.dol_print_date($i * 3600, 'hour', 'gmt').'
';
echo '
'."\n";
@@ -1524,8 +1626,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
$curtime = dol_mktime(0, 0, 0, $month, $day, $year);
$urltoshow = DOL_URL_ROOT.'/comm/action/index.php?action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year.$newparam;
$urltocreate = '';
- if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
- {
+ if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
$newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
$hourminsec = '100000';
$urltocreate = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $year, $month, $day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
@@ -1534,16 +1635,17 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
// Line with title of day
print '
'."\n";
- if ($nonew <= 0)
- {
+ if ($nonew <= 0) {
print '
';
- if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
- {
+ if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
print '
'; // Explicit link, usefull for nojs interfaces
print img_picto($langs->trans("NewAction"), 'edit_add.png');
print ' ';
@@ -1551,8 +1653,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print '
'."\n";
}
- if ($nonew < 0)
- {
+ if ($nonew < 0) {
print '
';
return;
}
@@ -1572,29 +1673,23 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
$tmpholiday = new Holiday($db);
- foreach ($eventarray as $daykey => $notused)
- {
+ foreach ($eventarray as $daykey => $notused) {
$annee = dol_print_date($daykey, '%Y');
$mois = dol_print_date($daykey, '%m');
$jour = dol_print_date($daykey, '%d');
- if ($day == $jour && $month == $mois && $year == $annee)
- {
- foreach ($eventarray[$daykey] as $index => $event)
- {
- if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA))
- {
+ if ($day == $jour && $month == $mois && $year == $annee) {
+ foreach ($eventarray[$daykey] as $index => $event) {
+ if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
$keysofuserassigned = array_keys($event->userassigned);
$ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
// Define $color (Hex string like '0088FF') and $cssclass of event
$color = -1; $cssclass = ''; $colorindex = -1;
- if (in_array($user->id, $keysofuserassigned))
- {
+ if (in_array($user->id, $keysofuserassigned)) {
$cssclass = 'family_mytasks';
- if (empty($cacheusers[$event->userownerid]))
- {
+ if (empty($cacheusers[$event->userownerid])) {
$newuser = new User($db);
$newuser->fetch($event->userownerid);
$cacheusers[$event->userownerid] = $newuser;
@@ -1602,9 +1697,10 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
//var_dump($cacheusers[$event->userownerid]->color);
// We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
- if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
- } elseif ($event->type_code == 'ICALEVENT') // Event come from external ical file
- {
+ if (!empty($cacheusers[$event->userownerid]->color)) {
+ $color = $cacheusers[$event->userownerid]->color;
+ }
+ } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
$numical++;
if (!empty($event->icalname)) {
if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
@@ -1615,37 +1711,37 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
$color = ($event->icalcolor ? $event->icalcolor : -1);
$cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
- } elseif ($event->type_code == 'BIRTHDAY')
- {
+ } elseif ($event->type_code == 'BIRTHDAY') {
$numbirthday++; $colorindex = 2; $cssclass = 'family_birthday '; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
} else {
$numother++;
$color = ($event->icalcolor ? $event->icalcolor : -1);
$cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
- if (empty($cacheusers[$event->userownerid]))
- {
+ if (empty($cacheusers[$event->userownerid])) {
$newuser = new User($db);
$newuser->fetch($event->userownerid);
$cacheusers[$event->userownerid] = $newuser;
}
//var_dump($cacheusers[$event->userownerid]->color);
- // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
- if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
+ // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
+ if (!empty($cacheusers[$event->userownerid]->color)) {
+ $color = $cacheusers[$event->userownerid]->color;
+ }
}
- if ($color < 0) // Color was not set on user card. Set color according to color index.
- {
+ if ($color < 0) { // Color was not set on user card. Set color according to color index.
// Define color index if not yet defined
$idusertouse = ($event->userownerid ? $event->userownerid : 0);
- if (isset($colorindexused[$idusertouse]))
- {
+ if (isset($colorindexused[$idusertouse])) {
$colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
} else {
- $colorindex = $nextindextouse;
- $colorindexused[$idusertouse] = $colorindex;
- if (!empty($theme_datacolor[$nextindextouse + 1])) $nextindextouse++; // Prepare to use next color
+ $colorindex = $nextindextouse;
+ $colorindexused[$idusertouse] = $colorindex;
+ if (!empty($theme_datacolor[$nextindextouse + 1])) {
+ $nextindextouse++; // Prepare to use next color
+ }
}
//print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'
';
// Define color
@@ -1666,14 +1762,12 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
$tmpyearend = date('Y', $event->date_end_in_calendar);
$tmpmonthend = date('m', $event->date_end_in_calendar);
$tmpdayend = date('d', $event->date_end_in_calendar);
- if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour)
- {
+ if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
$cssclass .= " unmovable";
}
} else {
if ($user->rights->agenda->allactions->create ||
- (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
- {
+ (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)) {
$cssclass .= " movable cursormove";
} else {
$cssclass .= " unmovable";
@@ -1681,8 +1775,12 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
}
$h = ''; $nowrapontd = 1;
- if ($action == 'show_day') { $h = 'height: 100%; '; $nowrapontd = 0; }
- if ($action == 'show_week') { $h = 'height: 100%; '; $nowrapontd = 0; }
+ if ($action == 'show_day') {
+ $h = 'height: 100%; '; $nowrapontd = 0;
+ }
+ if ($action == 'show_week') {
+ $h = 'height: 100%; '; $nowrapontd = 0;
+ }
// Show event box
print "\n";
@@ -1720,8 +1818,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print '" style="'.$h;
$colortouse = $color;
// If colortouse is similar than background, we force to change it.
- if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY))
- {
+ if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
print 'background: #f0f0f0;';
print 'border-left: 5px solid #'.$colortouse.';';
} else {
@@ -1729,8 +1826,8 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print 'border-left: 5px solid #'.dol_color_minus($colortouse, -3).';';
//print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
}
- //print 'background: #'.$colortouse.';';
- //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
+ //print 'background: #'.$colortouse.';';
+ //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
//if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
//else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
//print ' -moz-border-radius:4px;"';
@@ -1759,14 +1856,12 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print $listofusertoshow;
} else { // Other calendar
// Picto
- if (empty($event->fulldayevent))
- {
+ if (empty($event->fulldayevent)) {
//print $event->getNomUrl(2).' ';
}
// Date
- if (empty($event->fulldayevent))
- {
+ if (empty($event->fulldayevent)) {
// Show hours (start ... end)
$tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
$tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
@@ -1776,29 +1871,26 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
$tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
// Hour start
- if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
- {
+ if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
$daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
- $daterange .= '-';
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
+ if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
+ $daterange .= '-';
+ }
//else
//print '...';
}
}
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
- {
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
+ if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
$daterange .= '...';
}
}
// Hour end
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
- $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
+ if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
+ $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
+ }
}
} else {
if ($showinfo) {
@@ -1824,9 +1916,10 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
// Loop on each assigned user
$listofusertoshow = '';
$posuserassigned = 0;
- foreach ($event->userassigned as $tmpid => $tmpdata)
- {
- if (!$posuserassigned && $titletoshow) $listofusertoshow .= '
';
+ foreach ($event->userassigned as $tmpid => $tmpdata) {
+ if (!$posuserassigned && $titletoshow) {
+ $listofusertoshow .= '
';
+ }
$posuserassigned++;
if (empty($cacheusers[$tmpid])) {
$newuser = new User($db);
@@ -1840,48 +1933,57 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print $titletoshow;
print $listofusertoshow;
- if ($event->type_code == 'ICALEVENT') print '
('.dol_trunc($event->icalname, $maxnbofchar).')';
+ if ($event->type_code == 'ICALEVENT') {
+ print '
('.dol_trunc($event->icalname, $maxnbofchar).')';
+ }
$thirdparty_id = ($event->thirdparty_id > 0 ? $event->thirdparty_id : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
$contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
// If action related to company / contact
$linerelatedto = '';
- if ($thirdparty_id > 0)
- {
- if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id]))
- {
+ if ($thirdparty_id > 0) {
+ if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
$thirdparty = new Societe($db);
$thirdparty->fetch($thirdparty_id);
$cachethirdparties[$thirdparty_id] = $thirdparty;
- } else $thirdparty = $cachethirdparties[$thirdparty_id];
- if (!empty($thirdparty->id)) $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
+ } else {
+ $thirdparty = $cachethirdparties[$thirdparty_id];
+ }
+ if (!empty($thirdparty->id)) {
+ $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
+ }
}
- if (!empty($contact_id) && $contact_id > 0)
- {
- if (!is_object($cachecontacts[$contact_id]))
- {
+ if (!empty($contact_id) && $contact_id > 0) {
+ if (!is_object($cachecontacts[$contact_id])) {
$contact = new Contact($db);
$contact->fetch($contact_id);
$cachecontacts[$contact_id] = $contact;
- } else $contact = $cachecontacts[$contact_id];
- if ($linerelatedto) $linerelatedto .= ' ';
- if (!empty($contact->id)) $linerelatedto .= $contact->getNomUrl(1, '', 0);
+ } else {
+ $contact = $cachecontacts[$contact_id];
+ }
+ if ($linerelatedto) {
+ $linerelatedto .= ' ';
+ }
+ if (!empty($contact->id)) {
+ $linerelatedto .= $contact->getNomUrl(1, '', 0);
+ }
}
- if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
- {
+ if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- if ($linerelatedto) $linerelatedto .= '
';
+ if ($linerelatedto) {
+ $linerelatedto .= '
';
+ }
$linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
}
- if ($linerelatedto) print '
'.$linerelatedto;
+ if ($linerelatedto) {
+ print '
'.$linerelatedto;
+ }
}
// Show location
- if ($showinfo)
- {
- if ($event->location)
- {
+ if ($showinfo) {
+ if ($event->location) {
print '
';
print $langs->trans("Location").': '.$event->location;
}
@@ -1890,14 +1992,18 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print '';
// Status - Percent
$withstatus = 0;
- if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
- {
+ if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
$withstatus = 1;
- if ($event->percentage >= 0) $withstatus = 2;
+ if ($event->percentage >= 0) {
+ $withstatus = 2;
+ }
}
print '
';
- if ($withstatus) print $event->getLibStatut(3, 1);
- else print ' ';
+ if ($withstatus) {
+ print $event->getLibStatut(3, 1);
+ } else {
+ print ' ';
+ }
print ' ';
print ''."\n";
@@ -1923,8 +2029,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
print ' ';
}
- if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint)
- {
+ if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
print ''.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'
';
//print ' +'.(count($eventarray[$daykey])-$maxprint);
@@ -1963,8 +2068,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
function dol_color_minus($color, $minus, $minusunit = 16)
{
$newcolor = $color;
- if ($minusunit == 16)
- {
+ if ($minusunit == 16) {
$newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
$newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
$newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
@@ -1984,12 +2088,10 @@ function dol_color_minus($color, $minus, $minusunit = 16)
function sort_events_by_date($a, $b)
{
// Sort holidays at first
- if ($a->type_code === 'HOLIDAY')
- {
+ if ($a->type_code === 'HOLIDAY') {
return -1;
}
- if ($b->type_code === 'HOLIDAY')
- {
+ if ($b->type_code === 'HOLIDAY') {
return 1;
}
@@ -1997,20 +2099,17 @@ function sort_events_by_date($a, $b)
// datef => Event end time
// Events have different start time
- if ($a->datep !== $b->datep)
- {
+ if ($a->datep !== $b->datep) {
return $a->datep - $b->datep;
}
// Events have same start time and no end time
- if ((!is_numeric($b->datef)) || (!is_numeric($a->datef)))
- {
+ if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
return sort_events_by_percentage($a, $b);
}
// Events have the same start time and same end time
- if ($b->datef === $a->datef)
- {
+ if ($b->datef === $a->datef) {
return sort_events_by_percentage($a, $b);
}
@@ -2030,13 +2129,11 @@ function sort_events_by_percentage($a, $b)
// Sort events with no percentage before each other
// (usefull to sort holidays, sick days or similar on the top)
- if ($a->percentage < 0)
- {
+ if ($a->percentage < 0) {
return -1;
}
- if ($b->percentage < 0)
- {
+ if ($b->percentage < 0) {
return 1;
}
diff --git a/htdocs/comm/action/info.php b/htdocs/comm/action/info.php
index 40787abb8c3..2360f2925d9 100644
--- a/htdocs/comm/action/info.php
+++ b/htdocs/comm/action/info.php
@@ -39,8 +39,7 @@ $langs->load("commercial");
$id = GETPOST('id', 'int');
// Security check
-if ($user->socid > 0)
-{
+if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@@ -84,8 +83,7 @@ $morehtmlref = '';
// Thirdparty
//$morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
// Project
-if (!empty($conf->projet->enabled))
-{
+if (!empty($conf->projet->enabled)) {
$langs->load("projects");
//$morehtmlref.='
'.$langs->trans('Project') . ' ';
$morehtmlref .= $langs->trans('Project').': ';
@@ -95,7 +93,9 @@ if (!empty($conf->projet->enabled))
$morehtmlref .= '
';
$morehtmlref .= $proj->ref;
$morehtmlref .= ' ';
- if ($proj->title) $morehtmlref .= ' - '.$proj->title;
+ if ($proj->title) {
+ $morehtmlref .= ' - '.$proj->title;
+ }
} else {
$morehtmlref .= '';
}
diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php
index 68925c57bfa..64ed79d87ca 100644
--- a/htdocs/comm/action/list.php
+++ b/htdocs/comm/action/list.php
@@ -27,7 +27,9 @@
* \brief Page to list actions
*/
-if (!defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1);
+if (!defined("NOREDIRECTBYMAINTOLOGIN")) {
+ define('NOREDIRECTBYMAINTOLOGIN', 1);
+}
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
@@ -55,14 +57,17 @@ $toselect = GETPOST('toselect', 'array');
$confirm = GETPOST('confirm', 'alpha');
// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
-if (GETPOST('search_actioncode', 'array'))
-{
+if (GETPOST('search_actioncode', 'array')) {
$actioncode = GETPOST('search_actioncode', 'array', 3);
- if (!count($actioncode)) $actioncode = '0';
+ if (!count($actioncode)) {
+ $actioncode = '0';
+ }
} else {
$actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
}
-if ($actioncode == '' && empty($actioncodearray)) $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
+if ($actioncode == '' && empty($actioncodearray)) {
+ $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
+}
$search_id = GETPOST('search_id', 'alpha');
$search_title = GETPOST('search_title', 'alpha');
$search_note = GETPOST('search_note', 'alpha');
@@ -70,8 +75,12 @@ $search_note = GETPOST('search_note', 'alpha');
$dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'), 'tzuserrel');
$datestart = dol_mktime(0, 0, 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int'), 'tzuserrel');
$dateend = dol_mktime(0, 0, 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int'), 'tzuserrel');
-if ($search_status == '' && !GETPOSTISSET('search_status')) $search_status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
-if (empty($action) && !GETPOSTISSET('action')) $action = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
+if ($search_status == '' && !GETPOSTISSET('search_status')) {
+ $search_status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
+}
+if (empty($action) && !GETPOSTISSET('action')) {
+ $action = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
+}
$filter = GETPOST("search_filter", 'alpha', 3) ?GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
$filtert = GETPOST("search_filtert", "int", 3) ?GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
@@ -89,8 +98,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
// If not choice done on calendar owner, we filter on user.
-if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
-{
+if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
$filtert = $user->id;
}
@@ -98,30 +106,41 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if ($page == -1 || $page == null) { $page = 0; }
-$offset = $limit * $page;
-if (!$sortorder)
-{
- $sortorder = "DESC,DESC";
- if ($search_status == 'todo') $sortorder = "DESC,DESC";
+if ($page == -1 || $page == null) {
+ $page = 0;
}
-if (!$sortfield)
-{
+$offset = $limit * $page;
+if (!$sortorder) {
+ $sortorder = "DESC,DESC";
+ if ($search_status == 'todo') {
+ $sortorder = "DESC,DESC";
+ }
+}
+if (!$sortfield) {
$sortfield = "a.datep,a.id";
- if ($search_status == 'todo') $sortfield = "a.datep,a.id";
+ if ($search_status == 'todo') {
+ $sortfield = "a.datep,a.id";
+ }
}
// Security check
$socid = GETPOST("search_socid", 'int') ?GETPOST("search_socid", 'int') : GETPOST("socid", 'int');
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'agenda', 0, '', 'myactions');
-if ($socid < 0) $socid = '';
+if ($socid < 0) {
+ $socid = '';
+}
$canedit = 1;
-if (!$user->rights->agenda->myactions->read) accessforbidden();
-if (!$user->rights->agenda->allactions->read) $canedit = 0;
-if (!$user->rights->agenda->allactions->read || $filter == 'mine') // If no permission to see all, we show only affected to me
-{
+if (!$user->rights->agenda->myactions->read) {
+ accessforbidden();
+}
+if (!$user->rights->agenda->allactions->read) {
+ $canedit = 0;
+}
+if (!$user->rights->agenda->allactions->read || $filter == 'mine') { // If no permission to see all, we show only affected to me
$filtert = $user->id;
}
@@ -152,18 +171,14 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
* Actions
*/
-if (GETPOST('cancel', 'alpha'))
-{
+if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
-if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday"))
-{
+if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday")) {
$param = '';
- if (is_array($_POST))
- {
- foreach ($_POST as $key => $val)
- {
+ if (is_array($_POST)) {
+ foreach ($_POST as $key => $val) {
$param .= '&'.$key.'='.urlencode($val);
}
}
@@ -174,13 +189,14 @@ if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday"))
$parameters = array('id'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+if ($reshook < 0) {
+ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+}
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
-if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
-{
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
//$actioncode='';
$search_id = '';
$search_title = '';
@@ -192,12 +208,10 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$search_array_options = array();
}
-if (empty($reshook) && !empty($massaction))
-{
+if (empty($reshook) && !empty($massaction)) {
unset($percent);
- switch ($massaction)
- {
+ switch ($massaction) {
case 'set_all_events_to_todo':
$percent = ActionComm::EVENT_TODO;
break;
@@ -211,13 +225,10 @@ if (empty($reshook) && !empty($massaction))
break;
}
- if (isset($percent))
- {
- foreach ($toselect as $toselectid)
- {
+ if (isset($percent)) {
+ foreach ($toselect as $toselectid) {
$result = $object->updatePercent($toselectid, $percent);
- if ($result < 0)
- {
+ if ($result < 0) {
dol_print_error($db);
break;
}
@@ -226,8 +237,7 @@ if (empty($reshook) && !empty($massaction))
}
// As mass deletion happens with a confirm step, $massaction is not use for the final step (deletion).
-if (empty($reshook))
-{
+if (empty($reshook)) {
$objectclass = 'ActionComm';
$objectlabel = 'Events';
$uploaddir = true;
@@ -258,32 +268,78 @@ llxHeader('', $langs->trans("Agenda"), $help_url);
$listofextcals = array();
$param = '';
-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
-if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+}
+if ($limit > 0 && $limit != $conf->liste_limit) {
+ $param .= '&limit='.urlencode($limit);
+}
if ($actioncode != '') {
if (is_array($actioncode)) {
- foreach ($actioncode as $str_action) $param .= "&search_actioncode[]=".urlencode($str_action);
- } else $param .= "&search_actioncode=".urlencode($actioncode);
+ foreach ($actioncode as $str_action) {
+ $param .= "&search_actioncode[]=".urlencode($str_action);
+ }
+ } else {
+ $param .= "&search_actioncode=".urlencode($actioncode);
+ }
+}
+if ($resourceid > 0) {
+ $param .= "&search_resourceid=".urlencode($resourceid);
+}
+if ($search_status != '' && $search_status > -1) {
+ $param .= "&search_status=".urlencode($search_status);
+}
+if ($filter) {
+ $param .= "&search_filter=".urlencode($filter);
+}
+if ($filtert) {
+ $param .= "&search_filtert=".urlencode($filtert);
+}
+if ($usergroup > 0) {
+ $param .= "&search_usergroup=".urlencode($usergroup);
+}
+if ($socid > 0) {
+ $param .= "&search_socid=".urlencode($socid);
+}
+if ($showbirthday) {
+ $param .= "&search_showbirthday=1";
+}
+if ($pid) {
+ $param .= "&search_projectid=".urlencode($pid);
+}
+if ($type) {
+ $param .= "&search_type=".urlencode($type);
+}
+if ($search_id != '') {
+ $param .= '&search_title='.urlencode($search_id);
+}
+if ($search_title != '') {
+ $param .= '&search_title='.urlencode($search_title);
+}
+if ($search_note != '') {
+ $param .= '&search_note='.$search_note;
+}
+if (GETPOST('datestartday', 'int')) {
+ $param .= '&datestartday='.GETPOST('datestartday', 'int');
+}
+if (GETPOST('datestartmonth', 'int')) {
+ $param .= '&datestartmonth='.GETPOST('datestartmonth', 'int');
+}
+if (GETPOST('datestartyear', 'int')) {
+ $param .= '&datestartyear='.GETPOST('datestartyear', 'int');
+}
+if (GETPOST('dateendday', 'int')) {
+ $param .= '&dateendday='.GETPOST('dateendday', 'int');
+}
+if (GETPOST('dateendmonth', 'int')) {
+ $param .= '&dateendmonth='.GETPOST('dateendmonth', 'int');
+}
+if (GETPOST('dateendyear', 'int')) {
+ $param .= '&dateendyear='.GETPOST('dateendyear', 'int');
+}
+if ($optioncss != '') {
+ $param .= '&optioncss='.urlencode($optioncss);
}
-if ($resourceid > 0) $param .= "&search_resourceid=".urlencode($resourceid);
-if ($search_status != '' && $search_status > -1) $param .= "&search_status=".urlencode($search_status);
-if ($filter) $param .= "&search_filter=".urlencode($filter);
-if ($filtert) $param .= "&search_filtert=".urlencode($filtert);
-if ($usergroup > 0) $param .= "&search_usergroup=".urlencode($usergroup);
-if ($socid > 0) $param .= "&search_socid=".urlencode($socid);
-if ($showbirthday) $param .= "&search_showbirthday=1";
-if ($pid) $param .= "&search_projectid=".urlencode($pid);
-if ($type) $param .= "&search_type=".urlencode($type);
-if ($search_id != '') $param .= '&search_title='.urlencode($search_id);
-if ($search_title != '') $param .= '&search_title='.urlencode($search_title);
-if ($search_note != '') $param .= '&search_note='.$search_note;
-if (GETPOST('datestartday', 'int')) $param .= '&datestartday='.GETPOST('datestartday', 'int');
-if (GETPOST('datestartmonth', 'int')) $param .= '&datestartmonth='.GETPOST('datestartmonth', 'int');
-if (GETPOST('datestartyear', 'int')) $param .= '&datestartyear='.GETPOST('datestartyear', 'int');
-if (GETPOST('dateendday', 'int')) $param .= '&dateendday='.GETPOST('dateendday', 'int');
-if (GETPOST('dateendmonth', 'int')) $param .= '&dateendmonth='.GETPOST('dateendmonth', 'int');
-if (GETPOST('dateendyear', 'int')) $param .= '&dateendyear='.GETPOST('dateendyear', 'int');
-if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@@ -295,16 +351,21 @@ $arrayofmassactions = array(
'set_all_events_to_in_progress' => $langs->trans("SetAllEventsToInProgress"),
'set_all_events_to_finished' => $langs->trans("SetAllEventsToFinished"),
);
-if ($user->rights->agenda->allactions->delete)
-{
+if ($user->rights->agenda->allactions->delete) {
$arrayofmassactions['predelete'] = '
'.$langs->trans("Delete");
}
-if ($user->rights->agenda->myactions->create) $arrayofmassactions['preaffecttag'] = '
'.$langs->trans("AffectTag");
-if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array();
+if ($user->rights->agenda->myactions->create) {
+ $arrayofmassactions['preaffecttag'] = '
'.$langs->trans("AffectTag");
+}
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
+ $arrayofmassactions = array();
+}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
$sql = "SELECT";
-if ($usergroup > 0) $sql .= " DISTINCT";
+if ($usergroup > 0) {
+ $sql .= " DISTINCT";
+}
$sql .= " s.nom as societe, s.rowid as socid, s.client, s.email as socemail,";
$sql .= " a.id, a.code, a.label, a.note, a.datep as dp, a.datep2 as dp2, a.fulldayevent, a.location,";
$sql .= ' a.fk_user_author,a.fk_user_action,';
@@ -315,7 +376,9 @@ $sql .= " sp.lastname, sp.firstname, sp.email, sp.phone, sp.address, sp.phone as
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
- foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
+ }
}
// Add fields from hooks
@@ -325,34 +388,47 @@ $sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object) ";
-if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
+}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
$sql .= " ,".MAIN_DB_PREFIX."c_actioncomm as c";
// We must filter on resource table
-if ($resourceid > 0) $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
+if ($resourceid > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0) $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
-if ($usergroup > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
+if ($filtert > 0 || $usergroup > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
+}
+if ($usergroup > 0) {
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
+}
$sql .= " WHERE c.id = a.fk_action";
$sql .= ' AND a.entity IN ('.getEntity('agenda').')';
// Condition on actioncode
-if (!empty($actioncode))
-{
- if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
- {
- if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'";
- elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'";
- else {
- if ($actioncode == 'AC_OTH') $sql .= " AND c.type != 'systemauto'";
- if ($actioncode == 'AC_OTH_AUTO') $sql .= " AND c.type = 'systemauto'";
+if (!empty($actioncode)) {
+ if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
+ if ($actioncode == 'AC_NON_AUTO') {
+ $sql .= " AND c.type != 'systemauto'";
+ } elseif ($actioncode == 'AC_ALL_AUTO') {
+ $sql .= " AND c.type = 'systemauto'";
+ } else {
+ if ($actioncode == 'AC_OTH') {
+ $sql .= " AND c.type != 'systemauto'";
+ }
+ if ($actioncode == 'AC_OTH_AUTO') {
+ $sql .= " AND c.type = 'systemauto'";
+ }
}
} else {
- if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'";
- elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'";
- else {
- if (is_array($actioncode))
- {
+ if ($actioncode == 'AC_NON_AUTO') {
+ $sql .= " AND c.type != 'systemauto'";
+ } elseif ($actioncode == 'AC_ALL_AUTO') {
+ $sql .= " AND c.type = 'systemauto'";
+ } else {
+ if (is_array($actioncode)) {
$sql .= " AND c.code IN ('".implode("','", $actioncode)."')";
} else {
$sql .= " AND c.code IN ('".implode("','", explode(',', $actioncode))."')";
@@ -360,35 +436,74 @@ if (!empty($actioncode))
}
}
}
-if ($resourceid > 0) $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
-if ($pid) $sql .= " AND a.fk_project=".$db->escape($pid);
-if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")";
-if ($socid > 0) $sql .= " AND s.rowid = ".$socid;
+if ($resourceid > 0) {
+ $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
+}
+if ($pid) {
+ $sql .= " AND a.fk_project=".$db->escape($pid);
+}
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")";
+}
+if ($socid > 0) {
+ $sql .= " AND s.rowid = ".$socid;
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
-if ($type) $sql .= " AND c.id = ".(int) $type;
-if ($search_status == '0') { $sql .= " AND a.percent = 0"; }
-if ($search_status == 'na') { $sql .= " AND a.percent = -1"; } // Not applicable
-if ($search_status == '50') { $sql .= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
-if ($search_status == '100') { $sql .= " AND a.percent = 100"; }
-if ($search_status == 'done') { $sql .= " AND (a.percent = 100)"; }
-if ($search_status == 'todo') { $sql .= " AND (a.percent >= 0 AND a.percent < 100)"; }
-if ($search_id) $sql .= natural_search("a.id", $search_id, 1);
-if ($search_title) $sql .= natural_search("a.label", $search_title);
-if ($search_note) $sql .= natural_search('a.note', $search_note);
+if ($filtert > 0 || $usergroup > 0) {
+ $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
+}
+if ($type) {
+ $sql .= " AND c.id = ".(int) $type;
+}
+if ($search_status == '0') {
+ $sql .= " AND a.percent = 0";
+}
+if ($search_status == 'na') {
+ $sql .= " AND a.percent = -1";
+} // Not applicable
+if ($search_status == '50') {
+ $sql .= " AND (a.percent > 0 AND a.percent < 100)";
+} // Running already started
+if ($search_status == '100') {
+ $sql .= " AND a.percent = 100";
+}
+if ($search_status == 'done') {
+ $sql .= " AND (a.percent = 100)";
+}
+if ($search_status == 'todo') {
+ $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
+}
+if ($search_id) {
+ $sql .= natural_search("a.id", $search_id, 1);
+}
+if ($search_title) {
+ $sql .= natural_search("a.label", $search_title);
+}
+if ($search_note) {
+ $sql .= natural_search('a.note', $search_note);
+}
// We must filter on assignement table
-if ($filtert > 0 || $usergroup > 0)
-{
+if ($filtert > 0 || $usergroup > 0) {
$sql .= " AND (";
- if ($filtert > 0) $sql .= "(ar.fk_element = ".$filtert." OR (ar.fk_element IS NULL AND a.fk_user_action=".$filtert."))"; // The OR is for backward compatibility
- if ($usergroup > 0) $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup;
+ if ($filtert > 0) {
+ $sql .= "(ar.fk_element = ".$filtert." OR (ar.fk_element IS NULL AND a.fk_user_action=".$filtert."))"; // The OR is for backward compatibility
+ }
+ if ($usergroup > 0) {
+ $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup;
+ }
$sql .= ")";
}
// The second or of next test is to take event with no end date (we suppose duration is 1 hour in such case)
-if ($dateselect > 0) $sql .= " AND ((a.datep2 >= '".$db->idate($dateselect)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."') OR (a.datep2 IS NULL AND a.datep > '".$db->idate($dateselect - 3600)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."'))";
-if ($datestart > 0) $sql .= " AND a.datep BETWEEN '".$db->idate($datestart)."' AND '".$db->idate($datestart + 3600 * 24 - 1)."'";
-if ($dateend > 0) $sql .= " AND a.datep2 BETWEEN '".$db->idate($dateend)."' AND '".$db->idate($dateend + 3600 * 24 - 1)."'";
+if ($dateselect > 0) {
+ $sql .= " AND ((a.datep2 >= '".$db->idate($dateselect)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."') OR (a.datep2 IS NULL AND a.datep > '".$db->idate($dateselect - 3600)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."'))";
+}
+if ($datestart > 0) {
+ $sql .= " AND a.datep BETWEEN '".$db->idate($datestart)."' AND '".$db->idate($datestart + 3600 * 24 - 1)."'";
+}
+if ($dateend > 0) {
+ $sql .= " AND a.datep2 BETWEEN '".$db->idate($dateend)."' AND '".$db->idate($dateend + 3600 * 24 - 1)."'";
+}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
@@ -401,12 +516,10 @@ $sql .= $hookmanager->resPrint;
$sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
-if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
-{
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
- if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
- {
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@@ -417,8 +530,7 @@ $sql .= $db->plimit($limit + 1, $offset);
dol_syslog("comm/action/list.php", LOG_DEBUG);
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$actionstatic = new ActionComm($db);
$societestatic = new Societe($db);
@@ -438,7 +550,9 @@ if ($resql)
print '