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 .= '
 
'; } @@ -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 '
'."\n"; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; @@ -446,8 +560,12 @@ if ($resql) print ''; $nav = ''; - if ($filter) $nav .= ''; - if ($showbirthday) $nav .= ''; + if ($filter) { + $nav .= ''; + } + if ($showbirthday) { + $nav .= ''; + } print $nav; //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); @@ -457,19 +575,19 @@ if ($resql) // Add link to show birthdays $link = ''; /* - if (empty($conf->use_javascript_ajax)) - { - $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'; - $link=''; - if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents"); - else $link.=$langs->trans("AgendaHideBirthdayEvents"); - $link.=''; - } - */ + if (empty($conf->use_javascript_ajax)) + { + $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'; + $link=''; + if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents"); + else $link.=$langs->trans("AgendaHideBirthdayEvents"); + $link.=''; + } + */ $s = $newtitle; @@ -550,7 +668,9 @@ if ($resql) $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + if ($massactionbutton) { + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + } $i = 0; print '
'; @@ -561,11 +681,21 @@ if ($resql) print ''."\n"; print ''; - if (!empty($arrayfields['a.id']['checked'])) print ''; - if (!empty($arrayfields['owner']['checked'])) print ''; - if (!empty($arrayfields['c.libelle']['checked'])) print ''; - if (!empty($arrayfields['a.label']['checked'])) print ''; - if (!empty($arrayfields['a.note']['checked'])) print ''; + if (!empty($arrayfields['a.id']['checked'])) { + print ''; + } + if (!empty($arrayfields['owner']['checked'])) { + print ''; + } + if (!empty($arrayfields['c.libelle']['checked'])) { + print ''; + } + if (!empty($arrayfields['a.label']['checked'])) { + print ''; + } + if (!empty($arrayfields['a.note']['checked'])) { + print ''; + } if (!empty($arrayfields['a.datep']['checked'])) { print ''; } - if (!empty($arrayfields['a.fk_contact']['checked'])) print ''; - if (!empty($arrayfields['a.fk_element']['checked'])) print ''; + if (!empty($arrayfields['a.fk_contact']['checked'])) { + print ''; + } + if (!empty($arrayfields['a.fk_element']['checked'])) { + print ''; + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; @@ -590,8 +724,12 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (!empty($arrayfields['a.datec']['checked'])) print ''; - if (!empty($arrayfields['a.tms']['checked'])) print ''; + if (!empty($arrayfields['a.datec']['checked'])) { + print ''; + } + if (!empty($arrayfields['a.tms']['checked'])) { + print ''; + } if (!empty($arrayfields['a.percent']['checked'])) { print '\n"; print ''; - if (!empty($arrayfields['a.id']['checked'])) print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['owner']['checked'])) print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['c.libelle']['checked'])) print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['a.label']['checked'])) print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['a.note']['checked'])) print_liste_field_titre($arrayfields['a.note']['label'], $_SERVER["PHP_SELF"], "a.note", $param, "", "", $sortfield, $sortorder); + if (!empty($arrayfields['a.id']['checked'])) { + print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['owner']['checked'])) { + print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['c.libelle']['checked'])) { + print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['a.label']['checked'])) { + print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['a.note']['checked'])) { + print_liste_field_titre($arrayfields['a.note']['label'], $_SERVER["PHP_SELF"], "a.note", $param, "", "", $sortfield, $sortorder); + } //if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) - if (!empty($arrayfields['a.datep']['checked'])) print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep,a.id", $param, '', 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['a.datep2']['checked'])) print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['a.fk_contact']['checked'])) print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); - if (!empty($arrayfields['a.fk_element']['checked'])) print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); + if (!empty($arrayfields['a.datep']['checked'])) { + print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep,a.id", $param, '', 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['a.datep2']['checked'])) { + print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['s.nom']['checked'])) { + print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['a.fk_contact']['checked'])) { + print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); + } + if (!empty($arrayfields['a.fk_element']['checked'])) { + print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -626,10 +784,16 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (!empty($arrayfields['a.datec']['checked'])) print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['a.tms']['checked'])) print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", 'align="center"', $sortfield, $sortorder); + if (!empty($arrayfields['a.datec']['checked'])) { + print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['a.tms']['checked'])) { + print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", 'align="center"', $sortfield, $sortorder); + } - if (!empty($arrayfields['a.percent']['checked']))print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", 'align="center"', $sortfield, $sortorder); + if (!empty($arrayfields['a.percent']['checked'])) { + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", 'align="center"', $sortfield, $sortorder); + } print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print "\n"; @@ -642,13 +806,11 @@ if ($resql) $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1); $contactListCache = array(); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $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; } @@ -676,29 +838,34 @@ if ($resql) } // User owner - if (!empty($arrayfields['owner']['checked'])) - { + if (!empty($arrayfields['owner']['checked'])) { print ''; } // Type - if (!empty($arrayfields['c.libelle']['checked'])) - { + if (!empty($arrayfields['c.libelle']['checked'])) { print ''; @@ -726,11 +893,21 @@ if ($resql) print ''; } @@ -744,15 +921,16 @@ if ($resql) // Third party if (!empty($arrayfields['s.nom']['checked'])) { print ''; } @@ -760,17 +938,13 @@ if ($resql) if (!empty($arrayfields['a.fk_contact']['checked'])) { print ''; diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index 613ffee7be7..dc70fb30743 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -39,7 +39,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; -if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3; +if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) { + $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3; +} $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); @@ -49,31 +51,43 @@ $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", $showbirthday = 0; // 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; } $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "a.datec"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "a.datec"; +} // 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; } @@ -90,18 +104,20 @@ $type = GETPOST("search_type", 'alpha') ?GETPOST("search_type", 'alpha') : GETPO $maxprint = ((GETPOST("maxprint", 'int') != '') ?GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') // 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", "alpha") == '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); +} $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int')); -if ($dateselect > 0) -{ +if ($dateselect > 0) { $day = GETPOST('dateselectday', 'int'); $month = GETPOST('dateselectmonth', 'int'); $year = GETPOST('dateselectyear', 'int'); @@ -112,9 +128,15 @@ $tmp = str_replace(' ', '', $tmp); // FIX 7533 $tmparray = explode('-', $tmp); $begin_h = GETPOST('begin_h', 'int') != '' ?GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9); $end_h = GETPOST('end_h', 'int') ?GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18); -if ($begin_h < 0 || $begin_h > 23) $begin_h = 9; -if ($end_h < 1 || $end_h > 24) $end_h = 18; -if ($end_h <= $begin_h) $end_h = $begin_h + 1; +if ($begin_h < 0 || $begin_h > 23) { + $begin_h = 9; +} +if ($end_h < 1 || $end_h > 24) { + $end_h = 18; +} +if ($end_h <= $begin_h) { + $end_h = $begin_h + 1; +} $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS; $tmp = str_replace(' ', '', $tmp); // FIX 7533 @@ -122,8 +144,12 @@ $tmparray = explode('-', $tmp); $begin_d = 1; $end_d = 53; -if ($status == '' && !GETPOSTISSET('status')) $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 ($status == '' && !GETPOSTISSET('status')) { + $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 (GETPOST('viewcal', 'alpha') && $action != 'show_day' && $action != 'show_week' && $action != 'show_peruser') { $action = 'show_month'; $day = ''; @@ -149,8 +175,7 @@ $hookmanager->initHooks(array('agenda')); * Actions */ -if ($action == 'delete_action') -{ +if ($action == 'delete_action') { $event = new ActionComm($db); $event->fetch($actionid); $event->fetch_optionals(); @@ -185,7 +210,9 @@ $parameters = array( 'usergroup' => $usergroup, ); $reshook = $hookmanager->executeHooks('beforeAgendaPerType', $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'); +} $form = new Form($db); $companystatic = new Societe($db); @@ -223,29 +250,65 @@ $tmpday = $first_day; //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day; $title = $langs->trans("DoneAndToDoActions"); -if ($status == 'done') $title = $langs->trans("DoneActions"); -if ($status == 'todo') $title = $langs->trans("ToDoActions"); +if ($status == 'done') { + $title = $langs->trans("DoneActions"); +} +if ($status == 'todo') { + $title = $langs->trans("ToDoActions"); +} $param = ''; if ($actioncode || GETPOSTISSET('search_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 ($status || GETPOSTISSET('status')) { + $param .= "&search_status=".urlencode($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 ($action == 'show_day' || $action == 'show_week' || $action == 'show_month' || $action != 'show_peruser') { + $param .= '&action='.urlencode($action); +} +if ($begin_h != '') { + $param .= '&begin_h='.urlencode($begin_h); +} +if ($end_h != '') { + $param .= '&end_h='.urlencode($end_h); +} +if ($begin_d != '') { + $param .= '&begin_d='.urlencode($begin_d); +} +if ($end_d != '') { + $param .= '&end_d='.urlencode($end_d); } -if ($resourceid > 0) $param .= "&search_resourceid=".urlencode($resourceid); -if ($status || GETPOSTISSET('status')) $param .= "&search_status=".urlencode($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 ($action == 'show_day' || $action == 'show_week' || $action == 'show_month' || $action != 'show_peruser') $param .= '&action='.urlencode($action); -if ($begin_h != '') $param .= '&begin_h='.urlencode($begin_h); -if ($end_h != '') $param .= '&end_h='.urlencode($end_h); -if ($begin_d != '') $param .= '&begin_d='.urlencode($begin_d); -if ($end_d != '') $param .= '&end_d='.urlencode($end_d); $param .= "&maxprint=".urlencode($maxprint); $paramnoactionodate = $param; @@ -301,28 +364,23 @@ print 'use_javascript_ajax) -{ +if ($conf->use_javascript_ajax) { $s = ''; $s .= ''."\n"; - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { $s .= '
'.$langs->trans("LocalAgenda").'  
'; - if (is_array($showextcals) && count($showextcals) > 0) - { - foreach ($showextcals as $val) - { + if (is_array($showextcals) && count($showextcals) > 0) { + foreach ($showextcals as $val) { $htmlname = md5($val['name']); $s .= ''."\n"; - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { $s .= '
'.$langs->trans("LocalAgenda").'  
'; - if (is_array($showextcals) && count($showextcals) > 0) - { - foreach ($showextcals as $val) - { + if (is_array($showextcals) && count($showextcals) > 0) { + foreach ($showextcals as $val) { $htmlname = md5($val['name']); $s .= ''."\n"; - else print ''."\n"; + if (defined('JS_JQUERY') && constant('JS_JQUERY')) { + print ''."\n"; + } else { + print ''."\n"; + } /*if (! empty($conf->global->MAIN_FEATURES_LEVEL) && ! defined('JS_JQUERY_MIGRATE_DISABLED')) { if (defined('JS_JQUERY_MIGRATE') && constant('JS_JQUERY_MIGRATE')) print ''."\n"; else print ''."\n"; }*/ - if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) print ''."\n"; - else print ''."\n"; - if (!defined('DISABLE_JQUERY_TABLEDND')) print ''."\n"; + if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) { + print ''."\n"; + } else { + print ''."\n"; + } + if (!defined('DISABLE_JQUERY_TABLEDND')) { + print ''."\n"; + } // jQuery jnotify if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined('DISABLE_JQUERY_JNOTIFY')) { print ''."\n"; @@ -1502,16 +1583,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; print ''."\n"; // We include full because we need the support of containerCssClass } - if (!defined('DISABLE_MULTISELECT')) // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool - { + if (!defined('DISABLE_MULTISELECT')) { // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool print ''."\n"; } } if (!$disablejs && !empty($conf->use_javascript_ajax)) { // CKEditor - if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) - { + if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) { print ''."\n"; $pathckeditor = DOL_URL_ROOT.'/includes/ckeditor/ckeditor/'; $jsckeditor = 'ckeditor.js'; @@ -1520,7 +1599,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr $pathckeditor = constant('JS_CKEDITOR'); } print ''."\n"; } @@ -1554,27 +1635,21 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr print ''."\n"; // JS forced by modules (relative url starting with /) - if (!empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) - { + if (!empty($conf->modules_parts['js'])) { // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) $arrayjs = (array) $conf->modules_parts['js']; - foreach ($arrayjs as $modjs => $filesjs) - { + foreach ($arrayjs as $modjs => $filesjs) { $filesjs = (array) $filesjs; // To be sure filejs is an array - foreach ($filesjs as $jsfile) - { + foreach ($filesjs as $jsfile) { // jsfile is a relative path print ''."\n".''."\n"; } } } // JS forced by page in top_htmlhead (relative url starting with /) - if (is_array($arrayofjs)) - { + if (is_array($arrayofjs)) { print ''."\n"; - foreach ($arrayofjs as $jsfile) - { - if (preg_match('/^(http|\/\/)/i', $jsfile)) - { + foreach ($arrayofjs as $jsfile) { + if (preg_match('/^(http|\/\/)/i', $jsfile)) { print ''."\n"; } else { print ''."\n"; @@ -1583,8 +1658,12 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } - if (!empty($head)) print $head."\n"; - if (!empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n"; + if (!empty($head)) { + print $head."\n"; + } + if (!empty($conf->global->MAIN_HTML_HEADER)) { + print $conf->global->MAIN_HTML_HEADER."\n"; + } $parameters = array(); $result = $hookmanager->executeHooks('addHtmlHeader', $parameters); // Note that $action and $object may have been modified by some hooks @@ -1628,18 +1707,16 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead $toprightmenu = ''; // For backward compatibility with old modules - if (empty($conf->headerdone)) - { + if (empty($conf->headerdone)) { $disablenofollow = 0; top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow); print ''; } /* - * Top menu - */ - if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) - { + * Top menu + */ + if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) { if (!isset($form) || !is_object($form)) { include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; $form = new Form($db); @@ -1657,24 +1734,28 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead // Define link to login card $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) - { + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { $appli = $conf->global->MAIN_APPLICATION_TITLE; - if (preg_match('/\d\.\d/', $appli)) - { - if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core - } else $appli .= " ".DOL_VERSION; - } else $appli .= " ".DOL_VERSION; + if (preg_match('/\d\.\d/', $appli)) { + if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) { + $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + } else { + $appli .= " ".DOL_VERSION; + } + } else { + $appli .= " ".DOL_VERSION; + } - if (!empty($conf->global->MAIN_FEATURES_LEVEL)) $appli .= "
".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL; + if (!empty($conf->global->MAIN_FEATURES_LEVEL)) { + $appli .= "
".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL; + } $logouttext = ''; $logouthtmltext = ''; - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { //$logouthtmltext=$appli.'
'; - if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') - { + if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') { $logouthtmltext .= $langs->trans("Logout").'
'; $logouttext .= ''; @@ -1693,11 +1774,10 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead // Execute hook printTopRightMenu (hooks should output string like '') $parameters = array(); $result = $hookmanager->executeHooks('printTopRightMenu', $parameters); // Note that $action and $object may have been modified by some hooks - if (is_numeric($result)) - { - if ($result == 0) + if (is_numeric($result)) { + if ($result == 0) { $toprightmenu .= $hookmanager->resPrint; // add - else { + } else { $toprightmenu = $hookmanager->resPrint; // replace } } else { @@ -1705,8 +1785,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to module builder - if (!empty($conf->modulebuilder->enabled)) - { + if (!empty($conf->modulebuilder->enabled)) { $text = ''; //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"'); $text .= ''; @@ -1715,14 +1794,14 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to print main content area - if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') - { + if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') { $qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]); - if (is_array($_POST)) - { - foreach ($_POST as $key=>$value) { - if ($key !== 'action' && $key !== 'password' && !is_array($value)) $qs .= '&'.$key.'='.urlencode($value); + if (is_array($_POST)) { + foreach ($_POST as $key => $value) { + if ($key !== 'action' && $key !== 'password' && !is_array($value)) { + $qs .= '&'.$key.'='.urlencode($value); + } } } $qs .= (($qs && $morequerystring) ? '&' : '').$morequerystring; @@ -1734,8 +1813,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to Dolibarr wiki pages - if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $langs->load("help"); $helpbaseurl = ''; @@ -1756,21 +1834,28 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead $mode = $arrayres['mode']; // Link to help pages - if ($helpbaseurl && $helppage) - { + if ($helpbaseurl && $helppage) { $text = ''; $title = $langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage').'...'; if ($mode == 'wiki') { $title .= '
'.$langs->trans("PageWiki").' '.dol_escape_htmltag('"'.strtr($helppage, '_', ' ').'"'); - if ($helppresent) $title .= ' ('.$langs->trans("DedicatedPageAvailable").')'; - else $title .= ' ('.$langs->trans("HomePage").')'; + if ($helppresent) { + $title .= ' ('.$langs->trans("DedicatedPageAvailable").')'; + } else { + $title .= ' ('.$langs->trans("HomePage").')'; + } } $text .= '
'; $text .= ''; - if ($helppresent) $text .= ''; + if ($helppresent) { + $text .= ''; + } $text .= ''; $toprightmenu .= $form->textwithtooltip('', $title, 2, 1, $text, 'login_block_elem', 2); } @@ -1831,7 +1916,9 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead print "\n\n"; } - if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '
'; + if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) { + print '
'; + } } @@ -1849,14 +1936,17 @@ function top_menu_user($hideloginname = 0, $urllogout = '') global $menumanager; $userImage = $userDropDownImage = ''; - if (!empty($user->photo)) - { + if (!empty($user->photo)) { $userImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'photouserphoto userphoto', 'small', 0, 1); $userDropDownImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'dropdown-user-image', 'small', 0, 1); } else { $nophoto = '/public/theme/common/user_anonymous.png'; - if ($user->gender == 'man') $nophoto = '/public/theme/common/user_man.png'; - if ($user->gender == 'woman') $nophoto = '/public/theme/common/user_woman.png'; + if ($user->gender == 'man') { + $nophoto = '/public/theme/common/user_man.png'; + } + if ($user->gender == 'woman') { + $nophoto = '/public/theme/common/user_woman.png'; + } $userImage = 'No photo'; $userDropDownImage = 'No photo'; @@ -1870,8 +1960,7 @@ function top_menu_user($hideloginname = 0, $urllogout = '') if (!empty($user->admin)) { $dropdownBody .= '
'.$langs->trans("Administrator").': '.yn($user->admin); } - if (!empty($user->socid)) // Add thirdparty for external users - { + if (!empty($user->socid)) { // Add thirdparty for external users $thirdpartystatic = new Societe($db); $thirdpartystatic->fetch($user->socid); $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company @@ -1884,7 +1973,9 @@ function top_menu_user($hideloginname = 0, $urllogout = '') $dropdownBody .= '
'.$langs->trans("Session").''; $dropdownBody .= '
'.$langs->trans("IPAddress").': '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]); - if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $dropdownBody .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; + if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { + $dropdownBody .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; + } $dropdownBody .= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)'); $dropdownBody .= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser'); $dropdownBody .= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser'); @@ -1903,15 +1994,18 @@ function top_menu_user($hideloginname = 0, $urllogout = '') $dropdownBody .= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')'; $dropdownBody .= '
'.$langs->trans("Layout").': '.$conf->browser->layout; $dropdownBody .= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; - if ($conf->browser->layout == 'phone') $dropdownBody .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); - if (!empty($_SESSION["disablemodules"])) $dropdownBody .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + if ($conf->browser->layout == 'phone') { + $dropdownBody .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); + } + if (!empty($_SESSION["disablemodules"])) { + $dropdownBody .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + } $dropdownBody .= '
'; // Execute hook $parameters = array('user'=>$user, 'langs' => $langs); $result = $hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks - if (is_numeric($result)) - { + if (is_numeric($result)) { if ($result == 0) { $dropdownBody .= $hookmanager->resPrint; // add } else { @@ -1934,14 +2028,18 @@ function top_menu_user($hideloginname = 0, $urllogout = '') // Define version to show $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) - { + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { $appli = $conf->global->MAIN_APPLICATION_TITLE; - if (preg_match('/\d\.\d/', $appli)) - { - if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core - } else $appli .= " ".DOL_VERSION; - } else $appli .= " ".DOL_VERSION; + if (preg_match('/\d\.\d/', $appli)) { + if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) { + $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + } else { + $appli .= " ".DOL_VERSION; + } + } else { + $appli .= " ".DOL_VERSION; + } if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $btnUser = ' @@ -1990,8 +2088,7 @@ function top_menu_user($hideloginname = 0, $urllogout = '')
'; } - if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) // This may be set by some pages that use different jquery version to avoid errors - { + if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors $btnUser .= ' '."\n"; } // Wrapper to add log when clicking on download or preview - if (!empty($conf->blockedlog->enabled) && is_object($object) && $object->id > 0 && $object->statut > 0) - { - if (in_array($object->element, array('facture'))) // Restrict for the moment to element 'facture' - { + if (!empty($conf->blockedlog->enabled) && is_object($object) && $object->id > 0 && $object->statut > 0) { + if (in_array($object->element, array('facture'))) { // Restrict for the moment to element 'facture' print "\n\n"; ?> - + \n"; @@ -2916,20 +3063,17 @@ if (!function_exists("llxFooter")) // Add code for the asynchronous anonymous first ping (for telemetry) // You can use &forceping=1 in parameters to force the ping if the ping was already sent. $forceping = GETPOST('forceping', 'alpha'); - if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) - { + if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) { //print ''; $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id); if (empty($conf->global->MAIN_FIRST_PING_OK_DATE) || (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled')) - || $forceping) - { + || $forceping) { // No ping done if we are into an alpha version if (strpos('alpha', DOL_VERSION) > 0 && !$forceping) { print "\n\n"; - } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) // Cookie is set when we uncheck the checkbox in the installation wizard. - { - // MAIN_LAST_PING_KO_DATE + } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) { // Cookie is set when we uncheck the checkbox in the installation wizard. + // MAIN_LAST_PING_KO_DATE // Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent if (!empty($conf->global->MAIN_LAST_PING_KO_DATE) && substr($conf->global->MAIN_LAST_PING_KO_DATE, 0, 6) == dol_print_date(dol_now(), '%Y%m') && !$forceping) { print "\n\n"; @@ -2941,51 +3085,55 @@ if (!function_exists("llxFooter")) $url_for_ping = (empty($conf->global->MAIN_URL_FOR_PING) ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING); // Try to guess the distrib used $distrib = 'standard'; - if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') $distrib = 'doliwamp'; - if (!empty($dolibarr_distrib)) $distrib = $dolibarr_distrib; + if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') { + $distrib = 'doliwamp'; + } + if (!empty($dolibarr_distrib)) { + $distrib = $dolibarr_distrib; + } ?> - + db->host = $dolibarr_main_db_host; -$conf->db->port = $dolibarr_main_db_port; -$conf->db->name = $dolibarr_main_db_name; -$conf->db->user = $dolibarr_main_db_user; -$conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass; -$conf->db->type = $dolibarr_main_db_type; +$conf->db->host = $dolibarr_main_db_host; +$conf->db->port = $dolibarr_main_db_port; +$conf->db->name = $dolibarr_main_db_name; +$conf->db->user = $dolibarr_main_db_user; +$conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass; +$conf->db->type = $dolibarr_main_db_type; $conf->db->prefix = $dolibarr_main_db_prefix; $conf->db->character_set = $dolibarr_main_db_character_set; $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation; $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; -if (defined('TEST_DB_FORCE_TYPE')) $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example) +if (defined('TEST_DB_FORCE_TYPE')) { + $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example) +} // Set properties specific to conf file $conf->file->main_limit_users = $dolibarr_main_limit_users; @@ -68,18 +70,17 @@ $conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_ $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id; // Unique id of instance $conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define array of document root directories ('/home/htdocs') $conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define array of url root path ('' or '/dolibarr') -if (!empty($dolibarr_main_document_root_alt)) -{ +if (!empty($dolibarr_main_document_root_alt)) { // dolibarr_main_document_root_alt can contains several directories $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt); $i = 0; - foreach ($values as $value) $conf->file->dol_document_root['alt'.($i++)] = (string) $value; + foreach ($values as $value) { + $conf->file->dol_document_root['alt'.($i++)] = (string) $value; + } $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt); $i = 0; - foreach ($values as $value) - { - if (preg_match('/^http(s)?:/', $value)) - { + foreach ($values as $value) { + if (preg_match('/^http(s)?:/', $value)) { // Show error message $correct_value = str_replace($dolibarr_main_url_root, '', $value); print 'Error:
'."\n"; @@ -99,36 +100,39 @@ if (!empty($dolibarr_main_document_root_alt)) } // Chargement des includes principaux de librairies communes -if (!defined('NOREQUIREUSER')) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory -if (!defined('NOREQUIRETRAN')) require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; -if (!defined('NOREQUIRESOC')) require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; +if (!defined('NOREQUIREUSER')) { + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory +} +if (!defined('NOREQUIRETRAN')) { + require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; +} +if (!defined('NOREQUIRESOC')) { + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; +} /* * Creation objet $langs (must be before all other code) */ -if (!defined('NOREQUIRETRAN')) -{ +if (!defined('NOREQUIRETRAN')) { $langs = new Translate('', $conf); // Must be after reading conf } /* * Object $db */ -if (!defined('NOREQUIREDB')) -{ +if (!defined('NOREQUIREDB')) { $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port); - if ($db->error) - { + if ($db->error) { // If we were into a website context - if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) - { + if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) { $sapi_type = php_sapi_name(); - if (substr($sapi_type, 0, 3) != 'cgi') http_response_code(503); // To tel search engine this is a temporary error + if (substr($sapi_type, 0, 3) != 'cgi') { + http_response_code(503); // To tel search engine this is a temporary error + } print '
'; - if (is_object($langs)) - { + if (is_object($langs)) { $langs->setDefaultLang('auto'); $langs->load("website"); print $langs->trans("SorryWebsiteIsCurrentlyOffLine"); @@ -175,10 +179,11 @@ if (session_id() && !empty($_SESSION["dol_entity"])) { } // Sanitize entity -if (!is_numeric($conf->entity)) $conf->entity = 1; +if (!is_numeric($conf->entity)) { + $conf->entity = 1; +} -if (!defined('NOREQUIREDB')) -{ +if (!defined('NOREQUIREDB')) { //print "Will work with data into entity instance number '".$conf->entity."'"; // Here we read database (llx_const table) and define $conf->global->XXX var. @@ -197,23 +202,25 @@ if (!empty($conf->file->mailing_limit_sendbycli)) { } // Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr. -if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) -{ +if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) { require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $mysoc = new Societe($db); $mysoc->setMysoc($conf); // For some countries, we need to invert our address with customer address - if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1; + if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) { + $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1; + } } // Set default language (must be after the setValues setting global $conf->global->MAIN_LANG_DEFAULT. Page main.inc.php will overwrite langs->defaultlang with user value later) -if (!defined('NOREQUIRETRAN')) -{ +if (!defined('NOREQUIRETRAN')) { $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT)); - if (defined('MAIN_LANG_DEFAULT')) $langcode = constant('MAIN_LANG_DEFAULT'); + if (defined('MAIN_LANG_DEFAULT')) { + $langcode = constant('MAIN_LANG_DEFAULT'); + } $langs->setDefaultLang($langcode); } @@ -223,5 +230,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager = new HookManager($db); -if (!defined('MAIN_LABEL_MENTION_NPR')) define('MAIN_LABEL_MENTION_NPR', 'NPR'); +if (!defined('MAIN_LABEL_MENTION_NPR')) { + define('MAIN_LABEL_MENTION_NPR', 'NPR'); +} //if (! defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $conf->user->dir_temp); diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 983c7996898..e01bad39d77 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -28,48 +28,84 @@ //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} // Some value of modulepart can be used to get resources that are public so no login are required. // Note that only directory logo is free to access without login. -if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'mycompany' && preg_match('/^\/?logos\//', $_GET['file'])) -{ - if (!defined("NOLOGIN")) define("NOLOGIN", 1); - if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. - if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip +if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'mycompany' && preg_match('/^\/?logos\//', $_GET['file'])) { + if (!defined("NOLOGIN")) { + define("NOLOGIN", 1); + } + if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. + } + if (!defined("NOIPCHECK")) { + define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip + } } // For direct external download link, we don't need to load/check we are into a login session -if (isset($_GET["hashp"]) && !defined("NOLOGIN")) -{ - if (!defined("NOLOGIN")) define("NOLOGIN", 1); - if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. - if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip +if (isset($_GET["hashp"]) && !defined("NOLOGIN")) { + if (!defined("NOLOGIN")) { + define("NOLOGIN", 1); + } + if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. + } + if (!defined("NOIPCHECK")) { + define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip + } } // Some value of modulepart can be used to get resources that are public so no login are required. -if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'medias') -{ - if (!defined("NOLOGIN")) define("NOLOGIN", 1); - if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. - if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip +if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'medias') { + if (!defined("NOLOGIN")) { + define("NOLOGIN", 1); + } + if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. + } + if (!defined("NOIPCHECK")) { + define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip + } } // Used by TakePOS Auto Order -if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'product' && isset($_GET["publictakepos"])) -{ - if (!defined("NOLOGIN")) define("NOLOGIN", 1); - if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. - if (!defined("NOIPCHECK")) define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip +if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'product' && isset($_GET["publictakepos"])) { + if (!defined("NOLOGIN")) { + define("NOLOGIN", 1); + } + if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. + } + if (!defined("NOIPCHECK")) { + define("NOIPCHECK", 1); // Do not check IP defined into conf $dolibarr_main_restrict_ip + } } // For multicompany $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); -if (is_numeric($entity)) define("DOLENTITY", $entity); +if (is_numeric($entity)) { + define("DOLENTITY", $entity); +} /** * Header empty @@ -101,9 +137,15 @@ $urlsource = GETPOST('urlsource', 'alpha'); $entity = GETPOST('entity', 'int') ?GETPOST('entity', 'int') : $conf->entity; // Security check -if (empty($modulepart) && empty($hashp)) accessforbidden('Bad link. Bad value for parameter modulepart', 0, 0, 1); -if (empty($original_file) && empty($hashp) && $modulepart != 'barcode') accessforbidden('Bad link. Missing identification to find file (param file or hashp)', 0, 0, 1); -if ($modulepart == 'fckeditor') $modulepart = 'medias'; // For backward compatibility +if (empty($modulepart) && empty($hashp)) { + accessforbidden('Bad link. Bad value for parameter modulepart', 0, 0, 1); +} +if (empty($original_file) && empty($hashp) && $modulepart != 'barcode') { + accessforbidden('Bad link. Missing identification to find file (param file or hashp)', 0, 0, 1); +} +if ($modulepart == 'fckeditor') { + $modulepart = 'medias'; // For backward compatibility +} @@ -119,38 +161,33 @@ if ($modulepart == 'fckeditor') $modulepart = 'medias'; // For backward compatib * View */ -if (GETPOST("cache", 'alpha')) -{ +if (GETPOST("cache", 'alpha')) { // Important: Following code is to avoid page request by browser and PHP CPU at // each Dolibarr page access. - if (empty($dolibarr_nocache)) - { + if (empty($dolibarr_nocache)) { header('Cache-Control: max-age=3600, public, must-revalidate'); header('Pragma: cache'); // This is to avoid having Pragma: no-cache - } else header('Cache-Control: no-cache'); + } else { + header('Cache-Control: no-cache'); + } //print $dolibarr_nocache; exit; } // If we have a hash public (hashp), we guess the original_file. -if (!empty($hashp)) -{ +if (!empty($hashp)) { include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile = new EcmFiles($db); $result = $ecmfile->fetch(0, '', '', '', $hashp); - if ($result > 0) - { + if ($result > 0) { $tmp = explode('/', $ecmfile->filepath, 2); // $ecmfile->filepath is relative to document directory // filepath can be 'users/X' or 'X/propale/PR11111' - if (is_numeric($tmp[0])) // If first tmp is numeric, it is subdir of company for multicompany, we take next part. - { + if (is_numeric($tmp[0])) { // If first tmp is numeric, it is subdir of company for multicompany, we take next part. $tmp = explode('/', $tmp[1], 2); } $moduleparttocheck = $tmp[0]; // moduleparttocheck is first part of path - if ($modulepart) // Not required, so often not defined, for link using public hashp parameter. - { - if ($moduleparttocheck == $modulepart) - { + if ($modulepart) { // Not required, so often not defined, for link using public hashp parameter. + if ($moduleparttocheck == $modulepart) { // We remove first level of directory $original_file = (($tmp[1] ? $tmp[1].'/' : '').$ecmfile->filename); // this is relative to module dir //var_dump($original_file); exit; @@ -169,13 +206,20 @@ if (!empty($hashp)) // Define mime type $type = 'application/octet-stream'; -if (GETPOST('type', 'alpha')) $type = GETPOST('type', 'alpha'); -else $type = dol_mimetype($original_file); +if (GETPOST('type', 'alpha')) { + $type = GETPOST('type', 'alpha'); +} else { + $type = dol_mimetype($original_file); +} // Security: This wrapper is for images. We do not allow type/html -if (preg_match('/html/i', $type)) accessforbidden('Error: Using the image wrapper to output a file with a mime type HTML is not possible.', 0, 0, 1); +if (preg_match('/html/i', $type)) { + accessforbidden('Error: Using the image wrapper to output a file with a mime type HTML is not possible.', 0, 0, 1); +} // Security: This wrapper is for images. We do not allow files ending with .noexe -if (preg_match('/\.noexe$/i', $original_file)) accessforbidden('Error: Using the image wrapper to output a file ending with .noexe is not allowed.', 0, 0, 1); +if (preg_match('/\.noexe$/i', $original_file)) { + accessforbidden('Error: Using the image wrapper to output a file ending with .noexe is not allowed.', 0, 0, 1); +} // Security: Delete string ../ into $original_file $original_file = str_replace("../", "/", $original_file); @@ -184,7 +228,9 @@ $original_file = str_replace("../", "/", $original_file); $refname = basename(dirname($original_file)."/"); // Security check -if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart', 0, 0, 1); +if (empty($modulepart)) { + accessforbidden('Bad value for parameter modulepart', 0, 0, 1); +} $check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, $refname); $accessallowed = $check_access['accessallowed']; @@ -200,20 +246,15 @@ if (!empty($hashp)) { } } else { // Basic protection (against external users only) - if ($user->socid > 0) - { - if ($sqlprotectagainstexternals) - { + if ($user->socid > 0) { + if ($sqlprotectagainstexternals) { $resql = $db->query($sqlprotectagainstexternals); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); - if ($user->socid != $obj->fk_soc) - { + if ($user->socid != $obj->fk_soc) { $accessallowed = 0; break; } @@ -226,15 +267,13 @@ if (!empty($hashp)) { // Security: // Limit access if permissions are wrong -if (!$accessallowed) -{ +if (!$accessallowed) { accessforbidden(); } // Security: // On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers. -if (preg_match('/\.\./', $fullpath_original_file) || preg_match('/[<>|]/', $fullpath_original_file)) -{ +if (preg_match('/\.\./', $fullpath_original_file) || preg_match('/[<>|]/', $fullpath_original_file)) { dol_syslog("Refused to deliver file ".$fullpath_original_file); print "ErrorFileNameInvalid: ".dol_escape_htmltag($original_file); exit; @@ -242,15 +281,13 @@ if (preg_match('/\.\./', $fullpath_original_file) || preg_match('/[<>|]/', $full -if ($modulepart == 'barcode') -{ +if ($modulepart == 'barcode') { $generator = GETPOST("generator", "alpha"); $code = GETPOST("code", 'none'); // This can be rich content (qrcode, datamatrix, ...) $encoding = GETPOST("encoding", "alpha"); $readable = GETPOST("readable", 'alpha') ?GETPOST("readable", "alpha") : "Y"; - if (empty($generator) || empty($encoding)) - { + if (empty($generator) || empty($encoding)) { print 'Error: Parameter "generator" or "encoding" not defined'; exit; } @@ -259,23 +296,25 @@ if ($modulepart == 'barcode') $result = 0; - foreach ($dirbarcode as $reldir) - { + foreach ($dirbarcode as $reldir) { $dir = dol_buildpath($reldir, 0); $newdir = dol_osencode($dir); // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) - if (!is_dir($newdir)) continue; + if (!is_dir($newdir)) { + continue; + } $result = @include_once $newdir.$generator.'.modules.php'; - if ($result) break; + if ($result) { + break; + } } // Load barcode class $classname = "mod".ucfirst($generator); $module = new $classname($db); - if ($module->encodingIsSupported($encoding)) - { + if ($module->encodingIsSupported($encoding)) { $result = $module->buildBarCode($code, $encoding, $readable); } } else { @@ -288,17 +327,15 @@ if ($modulepart == 'barcode') dol_syslog("viewimage.php return file $fullpath_original_file filename=$filename content-type=$type"); // This test is to avoid error images when image is not available (for example thumbs). - if (!dol_is_file($fullpath_original_file) && empty($_GET["noalt"])) - { + if (!dol_is_file($fullpath_original_file) && empty($_GET["noalt"])) { $fullpath_original_file = DOL_DOCUMENT_ROOT.'/public/theme/common/nophoto.png'; /*$error='Error: File '.$_GET["file"].' does not exists or filesystems permissions are not allowed'; - print $error; - exit;*/ + print $error; + exit;*/ } // Permissions are ok and file found, so we return it - if ($type) - { + if ($type) { top_httphead($type); header('Content-Disposition: inline; filename="'.basename($fullpath_original_file).'"'); } else { @@ -312,4 +349,6 @@ if ($modulepart == 'barcode') } -if (is_object($db)) $db->close(); +if (is_object($db)) { + $db->close(); +}
'; print $form->selectDate($datestart, 'datestart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel'); @@ -579,8 +709,12 @@ if ($resql) if (!empty($arrayfields['s.nom']['checked'])) { print ''; $formactions->form_select_status_action('formaction', $search_status, 1, 'search_status', 1, 2, 'minwidth100imp maxwidth125'); @@ -606,17 +744,37 @@ if ($resql) print "
'; // With edge and chrome the td overflow is not supported correctly when content is not full text. - if ($obj->fk_user_action > 0) - { + if ($obj->fk_user_action > 0) { $userstatic->fetch($obj->fk_user_action); print $userstatic->getNomUrl(-1); - } else print ' '; + } else { + print ' '; + } print ''; print $actionstatic->getTypePicto(); $labeltype = $obj->type_code; - if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) $labeltype = 'AC_OTH'; + if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) { + $labeltype = 'AC_OTH'; + } if ($actionstatic->type_code == 'AC_OTH' && $actionstatic->code == 'TICKET_MSG') { $labeltype = $langs->trans("Message"); } else { - if (!empty($arraylist[$labeltype])) $labeltype = $arraylist[$labeltype]; - if ($obj->type_code == 'AC_OTH_AUTO' && ($obj->type_code != $obj->code) && $labeltype && !empty($arraylist[$obj->code])) $labeltype .= ' - '.$arraylist[$obj->code]; // Use code in priority on type_code + if (!empty($arraylist[$labeltype])) { + $labeltype = $arraylist[$labeltype]; + } + if ($obj->type_code == 'AC_OTH_AUTO' && ($obj->type_code != $obj->code) && $labeltype && !empty($arraylist[$obj->code])) { + $labeltype .= ' - '.$arraylist[$obj->code]; // Use code in priority on type_code + } } print dol_trunc($labeltype, 28); print ''; print dol_print_date($db->jdate($obj->dp), $formatToUse, 'tzuser'); $late = 0; - if ($obj->percent == 0 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) $late = 1; - if ($obj->percent == 0 && !$obj->dp && $obj->dp2 && $db->jdate($obj->dp) < ($now - $delay_warning)) $late = 1; - if ($obj->percent > 0 && $obj->percent < 100 && $obj->dp2 && $db->jdate($obj->dp2) < ($now - $delay_warning)) $late = 1; - if ($obj->percent > 0 && $obj->percent < 100 && !$obj->dp2 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) $late = 1; - if ($late) print img_warning($langs->trans("Late")).' '; + if ($obj->percent == 0 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) { + $late = 1; + } + if ($obj->percent == 0 && !$obj->dp && $obj->dp2 && $db->jdate($obj->dp) < ($now - $delay_warning)) { + $late = 1; + } + if ($obj->percent > 0 && $obj->percent < 100 && $obj->dp2 && $db->jdate($obj->dp2) < ($now - $delay_warning)) { + $late = 1; + } + if ($obj->percent > 0 && $obj->percent < 100 && !$obj->dp2 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) { + $late = 1; + } + if ($late) { + print img_warning($langs->trans("Late")).' '; + } print ''; - if ($obj->socid > 0) - { + if ($obj->socid > 0) { $societestatic->id = $obj->socid; $societestatic->client = $obj->client; $societestatic->name = $obj->societe; $societestatic->email = $obj->socemail; print $societestatic->getNomUrl(1, '', 28); - } else print ' '; + } else { + print ' '; + } print ''; - if (!empty($actionstatic->socpeopleassigned)) - { + if (!empty($actionstatic->socpeopleassigned)) { $contactList = array(); - foreach ($actionstatic->socpeopleassigned as $socpeopleassigned) - { - if (!isset($contactListCache[$socpeopleassigned['id']])) - { + foreach ($actionstatic->socpeopleassigned as $socpeopleassigned) { + if (!isset($contactListCache[$socpeopleassigned['id']])) { // if no cache found we fetch it $contact = new Contact($db); - if ($contact->fetch($socpeopleassigned['id']) > 0) - { + if ($contact->fetch($socpeopleassigned['id']) > 0) { $contactListCache[$socpeopleassigned['id']] = $contact->getNomUrl(1, '', 0); $contactList[] = $contact->getNomUrl(1, '', 0); } @@ -782,8 +956,7 @@ if ($resql) if (!empty($contactList)) { print implode(', ', $contactList); } - } elseif ($obj->fk_contact > 0) //keep for retrocompatibility with faraway event - { + } elseif ($obj->fk_contact > 0) { //keep for retrocompatibility with faraway event $contactstatic->id = $obj->fk_contact; $contactstatic->email = $obj->email; $contactstatic->lastname = $obj->lastname; @@ -835,10 +1008,11 @@ if ($resql) } // Action column print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->id, $arrayofselected)) $selected = 1; + if (in_array($obj->id, $arrayofselected)) { + $selected = 1; + } print ''; } print '