--- /tmp/dsg/dolibarr/htdocs/resource/github_agenda.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_agenda.php @@ -40,16 +40,18 @@ // Get parameters $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); if (GETPOST('actioncode', 'array')) { - $actioncode = GETPOST('actioncode', 'array', 3); - if (!count($actioncode)) $actioncode = '0'; -} else { - $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); + $actioncode = GETPOST('actioncode', 'array', 3); + if (!count($actioncode)) $actioncode = '0'; +} +else +{ + $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); } $search_agenda_label = GETPOST('search_agenda_label'); @@ -89,19 +91,19 @@ if (empty($reshook)) { - // Cancel - if (GETPOST('cancel', 'alpha') && !empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } + // Cancel + if (GETPOST('cancel', 'alpha') && !empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } - // 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 - { - $actioncode = ''; - $search_agenda_label = ''; - } + // 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 + { + $actioncode = ''; + $search_agenda_label = ''; + } } @@ -131,40 +133,40 @@ $head = resource_prepare_head($object); $titre = $langs->trans("ResourceSingular"); - print dol_get_fiche_head($head, 'agenda', $titre, -1, $picto); + dol_fiche_head($head, 'agenda', $titre, -1, $picto); - $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; + $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; - $morehtmlref = '<div class="refidno">'; - $morehtmlref .= '</div>'; + $morehtmlref = '<div class="refidno">'; + $morehtmlref .= '</div>'; - $shownav = 1; - if ($user->socid && !in_array('resource', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + $shownav = 1; + if ($user->socid && !in_array('resource', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - print '<div class="fichecenter">'; - print '<div class="underbanner clearboth"></div>'; + print '<div class="fichecenter">'; + print '<div class="underbanner clearboth"></div>'; print '</div>'; - print dol_get_fiche_end(); + dol_fiche_end(); - if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) - { - $param = '&id='.$object->id.'&socid='.$socid; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); + if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) + { + $param = '&id='.$object->id.'&socid='.$socid; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); print_barre_liste($langs->trans("ActionsOnResource"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlcenter, '', 0, 1, 1); - // List of all actions + // List of all actions $filters = array(); - $filters['search_agenda_label'] = $search_agenda_label; + $filters['search_agenda_label'] = $search_agenda_label; - // TODO Replace this with same code than into list.php - show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder); - } + // TODO Replace this with same code than into list.php + show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder); + } } // End of page --- /tmp/dsg/dolibarr/htdocs/resource/github_card.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_card.php @@ -35,11 +35,11 @@ // Get parameters $id = GETPOST('id', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $ref = GETPOST('ref', 'alpha'); -$description = GETPOST('description', 'restricthtml'); -$confirm = GETPOST('confirm', 'aZ09'); +$description = GETPOST('description'); +$confirm = GETPOST('confirm'); $fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $country_id = GETPOST('country_id', 'int'); @@ -99,7 +99,9 @@ { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); $action = 'create'; - } else { + } + else + { $object->ref = $ref; $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; @@ -116,13 +118,17 @@ setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else + { // Creation KO setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } } - } else { + } + else + { Header("Location: list.php"); exit; } @@ -159,11 +165,15 @@ { Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -187,10 +197,14 @@ setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null, 'mesgs'); Header('Location: '.DOL_URL_ROOT.'/resource/list.php'); exit; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -212,10 +226,12 @@ if ($action == 'create') { print load_fiche_titre($title, '', 'object_resource'); - print dol_get_fiche_head(''); - } else { + dol_fiche_head(''); + } + else + { $head = resource_prepare_head($object); - print dol_get_fiche_head($head, 'resource', $title, -1, 'resource'); + dol_fiche_head($head, 'resource', $title, -1, 'resource'); } if ($action == 'create' || $action == 'edit') @@ -257,7 +273,7 @@ // Other attributes $parameters = array('objectsrc' => $objectsrc); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; + print $hookmanager->resPrint; if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); @@ -265,41 +281,43 @@ print '</table>'; - print dol_get_fiche_end(); + dol_fiche_end(); print '<div class="center">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans($action == "create" ? "Create" : "Modify").'">'; print ' '; - print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; + print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; print '</div>'; print '</div>'; print '</form>'; - } else { + } + else + { $formconfirm = ''; // Confirm deleting resource line - if ($action == 'delete') - { - $formconfirm = $form->formconfirm("card.php?&id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', '', 1); - } - - // Print form confirm - print $formconfirm; - - - $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; - - - $morehtmlref = '<div class="refidno">'; - $morehtmlref .= '</div>'; - - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - - print '<div class="fichecenter">'; - print '<div class="underbanner clearboth"></div>'; + if ($action == 'delete') + { + $formconfirm = $form->formconfirm("card.php?&id=".$object->id, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResource"), "confirm_delete_resource", '', '', 1); + } + + // Print form confirm + print $formconfirm; + + + $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; + + + $morehtmlref = '<div class="refidno">'; + $morehtmlref .= '</div>'; + + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + + print '<div class="fichecenter">'; + print '<div class="underbanner clearboth"></div>'; /*--------------------------------------- * View object @@ -340,7 +358,7 @@ print '<div class="clearboth"></div><br>'; - print dol_get_fiche_end(); + dol_fiche_end(); } @@ -365,17 +383,18 @@ } if ($action != "delete" && $action != "create" && $action != "edit") { - // Delete resource - if ($user->rights->resource->delete) - { - print '<div class="inline-block divButAction">'; - print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans('Delete').'</a>'; - print '</div>'; - } + // Delete resource + if ($user->rights->resource->delete) + { + print '<div class="inline-block divButAction">'; + print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=delete" class="butActionDelete">'.$langs->trans('Delete').'</a>'; + print '</div>'; + } } } print '</div>'; -} else { +} +else { dol_print_error(); } --- /tmp/dsg/dolibarr/htdocs/resource/github_contact.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_contact.php @@ -36,7 +36,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); // Security check if ($user->socid) $socid = $user->socid; @@ -55,15 +55,16 @@ if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + $result = $object->add_contact($contactid, GETPOST('type', 'int'), GETPOST('source', 'alpha')); } if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else + { if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); @@ -90,7 +91,8 @@ { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else { dol_print_error($db); } } @@ -116,7 +118,7 @@ $head = resource_prepare_head($object); - print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource'); + dol_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource'); $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; @@ -148,7 +150,7 @@ print '</table>'; print '</div>'; - print dol_get_fiche_end(); + dol_fiche_end(); print '<br>'; --- /tmp/dsg/dolibarr/htdocs/resource/github_document.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_document.php @@ -40,7 +40,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); // Security check @@ -50,8 +50,8 @@ // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$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 $offset = $limit * $page; @@ -89,7 +89,7 @@ $head = resource_prepare_head($object); - print dol_get_fiche_head($head, 'documents', $langs->trans("ResourceSingular"), -1, 'resource'); + dol_fiche_head($head, 'documents', $langs->trans("ResourceSingular"), -1, 'resource'); // Build file list @@ -114,7 +114,7 @@ print '<div class="fichecenter">'; print '<div class="underbanner clearboth"></div>'; - print '<table class="border tableforfield centpercent">'; + print '<table class="border tableforfield centpercent">'; // Resource type print '<tr>'; @@ -124,19 +124,21 @@ print '</td>'; print '</tr>'; - print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; - print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>'; - print '</table>'; + print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; + print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>'; + print '</table>'; - print '</div>'; + print '</div>'; - print dol_get_fiche_end(); + dol_fiche_end(); - $modulepart = 'dolresource'; - $permission = $user->rights->resource->write; + $modulepart = 'dolresource'; + $permission = $user->rights->resource->write; - include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; -} else { + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ print $langs->trans("ErrorUnknown"); } --- /tmp/dsg/dolibarr/htdocs/resource/github_element_resource.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_element_resource.php @@ -29,11 +29,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; if (!empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; } // Load translation files required by the page @@ -46,7 +46,7 @@ */ if (!$user->rights->resource->read) - accessforbidden(); + accessforbidden(); $object = new Dolresource($db); @@ -71,8 +71,8 @@ if ($socid > 0) // Special for thirdparty { - $element_id = $socid; - $element = 'societe'; + $element_id = $socid; + $element = 'societe'; } @@ -87,7 +87,7 @@ if (empty($reshook)) { - $error = 0; + $error = 0; if ($action == 'add_element_resource' && !$cancel) { @@ -97,69 +97,71 @@ $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors'); $action = ''; - } else { + } + else + { $objstat = fetchObjectByElement($element_id, $element, $element_ref); $objstat->element = $element; // For externals module, we need to keep @xx - // TODO : add this check at update_linked_resource and when modifying event start or end date - // check if an event resource is already in use - if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $objstat->element == 'action' && $resource_type == 'dolresource' && intval($busy) == 1) { - $eventDateStart = $objstat->datep; - $eventDateEnd = $objstat->datef; - $isFullDayEvent = intval($objstat->fulldayevent); - if (empty($eventDateEnd)) { - if ($isFullDayEvent) { - $eventDateStartArr = dol_getdate($eventDateStart); - $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); - $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); - } - } - - $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($resource_type)."'"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($objstat->element)."'"; - $sql .= " WHERE er.resource_id = ".$resource_id; - $sql .= " AND er.busy = 1"; - $sql .= " AND ("; - - // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) - $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))"; - // event date end between ac.datep and ac.datep2 - if (!empty($eventDateEnd)) { - $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))"; - } - // event date start before ac.datep and event date end after ac.datep2 - $sql .= " OR ("; - $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'"; - if (!empty($eventDateEnd)) { - $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')"; - } - $sql .= ")"; - - $sql .= ")"; - $resql = $db->query($sql); - if (!$resql) { - $error++; - $objstat->error = $db->lasterror(); - $objstat->errors[] = $objstat->error; - } else { - if ($db->num_rows($resql) > 0) { - // already in use - $error++; - $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : '; - while ($obj = $db->fetch_object($resql)) { - $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']'); - } - $objstat->errors[] = $objstat->error; - } - $db->free($resql); - } - } - - if (!$error) { - $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); - } + // TODO : add this check at update_linked_resource and when modifying event start or end date + // check if an event resource is already in use + if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $objstat->element == 'action' && $resource_type == 'dolresource' && intval($busy) == 1) { + $eventDateStart = $objstat->datep; + $eventDateEnd = $objstat->datef; + $isFullDayEvent = intval($objstat->fulldayevent); + if (empty($eventDateEnd)) { + if ($isFullDayEvent) { + $eventDateStartArr = dol_getdate($eventDateStart); + $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); + $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); + } + } + + $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; + $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($resource_type)."'"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($objstat->element)."'"; + $sql .= " WHERE er.resource_id = ".$resource_id; + $sql .= " AND er.busy = 1"; + $sql .= " AND ("; + + // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) + $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))"; + // event date end between ac.datep and ac.datep2 + if (!empty($eventDateEnd)) { + $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))"; + } + // event date start before ac.datep and event date end after ac.datep2 + $sql .= " OR ("; + $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'"; + if (!empty($eventDateEnd)) { + $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')"; + } + $sql .= ")"; + + $sql .= ")"; + $resql = $db->query($sql); + if (!$resql) { + $error++; + $objstat->error = $db->lasterror(); + $objstat->errors[] = $objstat->error; + } else { + if ($db->num_rows($resql) > 0) { + // already in use + $error++; + $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : '; + while ($obj = $db->fetch_object($resql)) { + $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']'); + } + $objstat->errors[] = $objstat->error; + } + $db->free($resql); + } + } + + if (!$error) { + $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); + } } if (!$error && $res > 0) @@ -167,7 +169,8 @@ setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs'); header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id); exit; - } elseif ($objstat) + } + elseif ($objstat) { setEventMessages($objstat->error, $objstat->errors, 'errors'); } @@ -182,68 +185,68 @@ $object->busy = $busy; $object->mandatory = $mandatory; - if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) { - $eventDateStart = $object->objelement->datep; - $eventDateEnd = $object->objelement->datef; - $isFullDayEvent = intval($objstat->fulldayevent); - if (empty($eventDateEnd)) { - if ($isFullDayEvent) { - $eventDateStartArr = dol_getdate($eventDateStart); - $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); - $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); - } - } - - $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'"; - $sql .= " WHERE er.resource_id = ".$object->resource_id; - $sql .= " AND ac.id != ".$object->element_id; - $sql .= " AND er.busy = 1"; - $sql .= " AND ("; - - // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) - $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))"; - // event date end between ac.datep and ac.datep2 - if (!empty($eventDateEnd)) { - $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))"; - } - // event date start before ac.datep and event date end after ac.datep2 - $sql .= " OR ("; - $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'"; - if (!empty($eventDateEnd)) { - $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')"; - } - $sql .= ")"; - - $sql .= ")"; - $resql = $db->query($sql); - if (!$resql) { - $error++; - $object->error = $db->lasterror(); - $object->errors[] = $object->error; - } else { - if ($db->num_rows($resql) > 0) { - // already in use - $error++; - $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : '; - while ($obj = $db->fetch_object($resql)) { - $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']'); - } - $object->errors[] = $objstat->error; - } - $db->free($resql); - } - } - - if (!$error) { - $result = $object->update_element_resource($user); - if ($result < 0) $error++; - } + if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) { + $eventDateStart = $object->objelement->datep; + $eventDateEnd = $object->objelement->datef; + $isFullDayEvent = intval($objstat->fulldayevent); + if (empty($eventDateEnd)) { + if ($isFullDayEvent) { + $eventDateStartArr = dol_getdate($eventDateStart); + $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); + $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']); + } + } + + $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label"; + $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'"; + $sql .= " WHERE er.resource_id = ".$object->resource_id; + $sql .= " AND ac.id != ".$object->element_id; + $sql .= " AND er.busy = 1"; + $sql .= " AND ("; + + // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end) + $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))"; + // event date end between ac.datep and ac.datep2 + if (!empty($eventDateEnd)) { + $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))"; + } + // event date start before ac.datep and event date end after ac.datep2 + $sql .= " OR ("; + $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'"; + if (!empty($eventDateEnd)) { + $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')"; + } + $sql .= ")"; + + $sql .= ")"; + $resql = $db->query($sql); + if (!$resql) { + $error++; + $object->error = $db->lasterror(); + $object->errors[] = $object->error; + } else { + if ($db->num_rows($resql) > 0) { + // already in use + $error++; + $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : '; + while ($obj = $db->fetch_object($resql)) { + $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']'); + } + $object->errors[] = $objstat->error; + } + $db->free($resql); + } + } + + if (!$error) { + $result = $object->update_element_resource($user); + if ($result < 0) $error++; + } if ($error) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs'); header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id); @@ -262,7 +265,9 @@ setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs'); header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id); exit; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -287,12 +292,14 @@ // Load available resource, declared by modules $ret = count($object->available_resources); if ($ret == -1) { - dol_print_error($db, $object->error); - exit; + dol_print_error($db, $object->error); + exit; } if (!$ret) { - print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>'; -} else { + print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>'; +} +else +{ // Confirmation suppression resource line if ($action == 'delete_resource') { @@ -310,10 +317,10 @@ { $head = actions_prepare_head($act); - print dol_get_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action'); + dol_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action'); $linkback = img_picto($langs->trans("BackToList"), 'object_list', 'class="hideonsmartphone pictoactionview"'); - $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?action=show_list">'.$langs->trans("BackToList").'</a>'; + $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php">'.$langs->trans("BackToList").'</a>'; // Link to other agenda views $out = ''; @@ -334,19 +341,19 @@ // Project if (!empty($conf->projet->enabled)) { - $langs->load("projects"); - //$morehtmlref.='<br>'.$langs->trans('Project') . ' '; - $morehtmlref .= $langs->trans('Project').': '; - if (!empty($act->fk_project)) { - $proj = new Project($db); - $proj->fetch($act->fk_project); - $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$act->fk_project.'" title="'.$langs->trans('ShowProject').'">'; - $morehtmlref .= $proj->ref; - $morehtmlref .= '</a>'; - if ($proj->title) $morehtmlref .= ' - '.$proj->title; - } else { - $morehtmlref .= ''; - } + $langs->load("projects"); + //$morehtmlref.='<br>'.$langs->trans('Project') . ' '; + $morehtmlref .= $langs->trans('Project').': '; + if (!empty($act->fk_project)) { + $proj = new Project($db); + $proj->fetch($act->fk_project); + $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$act->fk_project.'" title="'.$langs->trans('ShowProject').'">'; + $morehtmlref .= $proj->ref; + $morehtmlref .= '</a>'; + if ($proj->title) $morehtmlref .= ' - '.$proj->title; + } else { + $morehtmlref .= ''; + } } $morehtmlref .= '</div>'; @@ -404,7 +411,9 @@ } } $_SESSION['assignedtouser'] = json_encode($listofuserid); - } else { + } + else + { if (!empty($_SESSION['assignedtouser'])) { $listofuserid = json_decode($_SESSION['assignedtouser'], true); @@ -427,11 +436,11 @@ print '</div>'; - print dol_get_fiche_end(); - } - } - - // Specific to thirdparty module + dol_fiche_end(); + } + } + + // Specific to thirdparty module if (($element_id || $element_ref) && $element == 'societe') { $socstatic = fetchObjectByElement($element_id, $element, $element_ref); @@ -442,7 +451,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $head = societe_prepare_head($socstatic); - print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company'); + dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company'); dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element); @@ -460,7 +469,7 @@ print '</div>'; - print dol_get_fiche_end(); + dol_fiche_end(); $object = $savobject; } @@ -471,14 +480,14 @@ { require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; - $fichinter = new Fichinter($db); - $fichinter->fetch($element_id, $element_ref); - $fichinter->fetch_thirdparty(); + $fichinter = new Fichinter($db); + $fichinter->fetch($element_id, $element_ref); + $fichinter->fetch_thirdparty(); if (is_object($fichinter)) { $head = fichinter_prepare_head($fichinter); - print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention'); + dol_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention'); // Intervention card $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; @@ -527,17 +536,17 @@ dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1); - print dol_get_fiche_end(); + dol_fiche_end(); } } // Specific to product/service module if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; - - $product = new Product($db); - $product->fetch($element_id, $element_ref); + require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; + + $product = new Product($db); + $product->fetch($element_id, $element_ref); if (is_object($product)) { @@ -545,14 +554,14 @@ $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); - print dol_get_fiche_head($head, 'resources', $titre, -1, $picto); - - $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + dol_fiche_head($head, 'resources', $titre, -1, $picto); + + $shownav = 1; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element); - print dol_get_fiche_end(); - } + dol_fiche_end(); + } } @@ -591,7 +600,9 @@ if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) { $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'); - } else { + } + else + { $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php'; } if (empty($conf->file->strict_mode)) { @@ -609,7 +620,9 @@ if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) { $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'); - } else { + } + else + { $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php'; } if (empty($conf->file->strict_mode)) { --- /tmp/dsg/dolibarr/htdocs/resource/github_list.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_list.php @@ -39,7 +39,7 @@ $resource_id = GETPOST('resource_id', 'int'); $sortorder = GETPOST('sortorder', 'alpha'); -$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); // Initialize context for list $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist'; @@ -108,7 +108,7 @@ $pagenext = $page + 1; if (!$user->rights->resource->read) { - accessforbidden(); + accessforbidden(); } $arrayfields = array( 't.ref' => array( @@ -121,8 +121,14 @@ ), ); // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -195,8 +201,8 @@ $newcardbutton = ''; if ($user->rights->resource->write) { - $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create'); - } + $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create'); + } print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1); } @@ -240,45 +246,47 @@ if ($ret) { foreach ($object->lines as $resource) - { - print '<tr class="oddeven">'; - - if (!empty($arrayfields['t.ref']['checked'])) - { - print '<td>'; - print $resource->getNomUrl(5); - print '</td>'; - if (!$i) $totalarray['nbfield']++; - } - - if (!empty($arrayfields['ty.label']['checked'])) - { - print '<td>'; - print $resource->type_label; - print '</td>'; - if (!$i) $totalarray['nbfield']++; - } - // Extra fields - $obj = (Object) $resource->array_options; - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - - print '<td class="center">'; - print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">'; - print img_edit(); - print '</a>'; - print ' '; - print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">'; - print img_delete('', 'class="marginleftonly"'); - print '</a>'; - print '</td>'; - if (!$i) $totalarray['nbfield']++; - - print '</tr>'; - } -} else { - $colspan = 1; - foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } - print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; + { + print '<tr class="oddeven">'; + + if (!empty($arrayfields['t.ref']['checked'])) + { + print '<td>'; + print $resource->getNomUrl(5); + print '</td>'; + if (!$i) $totalarray['nbfield']++; + } + + if (!empty($arrayfields['ty.label']['checked'])) + { + print '<td>'; + print $resource->type_label; + print '</td>'; + if (!$i) $totalarray['nbfield']++; + } + // Extra fields + $obj = (Object) $resource->array_options; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + + print '<td class="center">'; + print '<a class="editfielda" href="./card.php?action=edit&id='.$resource->id.'">'; + print img_edit(); + print '</a>'; + print ' '; + print '<a href="./card.php?action=delete&id='.$resource->id.'">'; + print img_delete('', 'class="marginleftonly"'); + print '</a>'; + print '</td>'; + if (!$i) $totalarray['nbfield']++; + + print '</tr>'; + } +} +else +{ + $colspan = 1; + foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; } print '</table>'; --- /tmp/dsg/dolibarr/htdocs/resource/github_note.php +++ /tmp/dsg/dolibarr/htdocs/resource/client_note.php @@ -34,7 +34,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); // Security check if ($user->socid) $socid = $user->socid; @@ -64,7 +64,7 @@ if ($id > 0 || !empty($ref)) { $head = resource_prepare_head($object); - print dol_get_fiche_head($head, 'note', $langs->trans('ResourceSingular'), -1, 'resource'); + dol_fiche_head($head, 'note', $langs->trans('ResourceSingular'), -1, 'resource'); $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; @@ -97,7 +97,7 @@ $cssclass = 'titlefield'; include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; - print dol_get_fiche_end(); + dol_fiche_end(); } // End of page