agenda.lib.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. /* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/lib/agenda.lib.php
  22. * \brief Set of function for the agenda module
  23. */
  24. /**
  25. * Show filter form in agenda view
  26. *
  27. * @param Object $form Form object
  28. * @param int $canedit Can edit filter fields
  29. * @param int $status Status
  30. * @param int $year Year
  31. * @param int $month Month
  32. * @param int $day Day
  33. * @param int $showbirthday Show birthday
  34. * @param string $filtera Filter on create by user
  35. * @param string $filtert Filter on assigned to user
  36. * @param string $filterd Filter of done by user
  37. * @param int $pid Product id
  38. * @param int $socid Third party id
  39. * @param array $showextcals Array with list of external calendars, or -1 to show no legend
  40. * @param string $actioncode Preselected value of actioncode for filter on type
  41. * @return void
  42. */
  43. function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $showextcals=array(), $actioncode='') {
  44. global $conf, $user, $langs, $db;
  45. // Filters
  46. print '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  47. print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  48. print '<input type="hidden" name="status" value="' . $status . '">';
  49. print '<input type="hidden" name="year" value="' . $year . '">';
  50. print '<input type="hidden" name="month" value="' . $month . '">';
  51. print '<input type="hidden" name="day" value="' . $day . '">';
  52. print '<input type="hidden" name="showbirthday" value="' . $showbirthday . '">';
  53. print '<table class="nobordernopadding" width="100%">';
  54. print '<tr><td class="nowrap">';
  55. print '<table class="nobordernopadding">';
  56. if ($canedit)
  57. {
  58. print '<tr>';
  59. print '<td class="nowrap">';
  60. print $langs->trans("ActionsAskedBy");
  61. print ' &nbsp;</td><td class="nowrap maxwidthonsmartphone">';
  62. print $form->select_dolusers($filtera, 'userasked', 1, '', ! $canedit);
  63. print '</td>';
  64. print '</tr>';
  65. print '<tr>';
  66. print '<td class="nowrap">';
  67. print $langs->trans("or") . ' ' . $langs->trans("ActionsToDoBy");
  68. print ' &nbsp;</td><td class="nowrap maxwidthonsmartphone">';
  69. print $form->select_dolusers($filtert, 'usertodo', 1, '', ! $canedit);
  70. print '</td></tr>';
  71. print '<tr>';
  72. print '<td class="nowrap">';
  73. print $langs->trans("or") . ' ' . $langs->trans("ActionsDoneBy");
  74. print ' &nbsp;</td><td class="nowrap maxwidthonsmartphone">';
  75. print $form->select_dolusers($filterd, 'userdone', 1, '', ! $canedit);
  76. print '</td></tr>';
  77. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  78. $formactions=new FormActions($db);
  79. print '<tr>';
  80. print '<td class="nowrap">';
  81. print $langs->trans("Type");
  82. print ' &nbsp;</td><td class="nowrap maxwidthonsmartphone">';
  83. print $formactions->select_type_actions($actioncode, "actioncode", '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0));
  84. print '</td></tr>';
  85. }
  86. if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
  87. {
  88. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  89. $formproject=new FormProjets($db);
  90. print '<tr>';
  91. print '<td class="nowrap">';
  92. print $langs->trans("Project").' &nbsp; ';
  93. print '</td><td class="nowrap maxwidthonsmartphone">';
  94. $formproject->select_projects($socid?$socid:-1, $pid, 'projectid', 64);
  95. print '</td></tr>';
  96. }
  97. print '</table>';
  98. print '</td>';
  99. // Buttons
  100. print '<td align="center" valign="middle" class="nowrap">';
  101. print img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewcal" value="' . $langs->trans("ViewCal") . '">';
  102. print '<br>';
  103. print img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewweek" value="' . $langs->trans("ViewWeek") . '">';
  104. print '<br>';
  105. print img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewday" value="' . $langs->trans("ViewDay") . '">';
  106. print '<br>';
  107. print img_picto($langs->trans("ViewList"), 'object_list', 'class="hideonsmartphone"') . ' <input type="submit" class="button" style="min-width:120px" name="viewlist" value="' . $langs->trans("ViewList") . '">';
  108. print '</td>';
  109. // Legend
  110. if ($conf->use_javascript_ajax && is_array($showextcals))
  111. {
  112. print '<td align="center" valign="middle" class="nowrap">';
  113. print '<script type="text/javascript">' . "\n";
  114. print 'jQuery(document).ready(function () {' . "\n";
  115. print 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });' . "\n";
  116. print 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n";
  117. print 'jQuery(".family_birthday").toggle();' . "\n";
  118. print '});' . "\n";
  119. print '</script>' . "\n";
  120. print '<table>';
  121. if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA))
  122. {
  123. if (count($showextcals) > 0)
  124. {
  125. print '<tr><td><input type="checkbox" id="check_mytasks" name="check_mytasks" checked="true" disabled="disabled"> ' . $langs->trans("LocalAgenda") . '</td></tr>';
  126. foreach ($showextcals as $val)
  127. {
  128. $htmlname = dol_string_nospecial($val['name']);
  129. print '<tr><td>';
  130. print '<script type="text/javascript">' . "\n";
  131. print 'jQuery(document).ready(function () {' . "\n";
  132. print 'jQuery("#check_' . $htmlname . '").click(function() { jQuery(".family_' . $htmlname . '").toggle(); });' . "\n";
  133. print '});' . "\n";
  134. print '</script>' . "\n";
  135. print '<input type="checkbox" id="check_' . $htmlname . '" name="check_' . $htmlname . '" checked="true"> ' . $val ['name'];
  136. print '</td></tr>';
  137. }
  138. }
  139. }
  140. print '<tr><td>'.$langs->trans("AgendaShowBirthdayEvents").' <input type="checkbox" id="check_birthday" name="check_birthday"></td></tr>';
  141. print '</table>';
  142. print '</td>';
  143. }
  144. print '</tr>';
  145. print '</table>';
  146. print '</form>';
  147. }
  148. /**
  149. * Show actions to do array
  150. *
  151. * @param int $max Max nb of records
  152. * @return void
  153. */
  154. function show_array_actions_to_do($max=5)
  155. {
  156. global $langs, $conf, $user, $db, $bc, $socid;
  157. $now=dol_now();
  158. include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  159. include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  160. $sql = "SELECT a.id, a.label, a.datep as dp, a.datep2 as dp2, a.fk_user_author, a.percent,";
  161. $sql.= " c.code, c.libelle,";
  162. $sql.= " s.nom as sname, s.rowid, s.client";
  163. $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN ";
  164. $sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action";
  165. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  166. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  167. $sql.= " WHERE a.entity = ".$conf->entity;
  168. $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))";
  169. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  170. if ($socid) $sql.= " AND s.rowid = ".$socid;
  171. $sql.= " ORDER BY a.datep DESC, a.id DESC";
  172. $sql.= $db->plimit($max, 0);
  173. $resql=$db->query($sql);
  174. if ($resql)
  175. {
  176. $num = $db->num_rows($resql);
  177. print '<table class="noborder" width="100%">';
  178. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastActionsToDo",$max).'</td>';
  179. print '<td colspan="2" align="right"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?status=todo">'.$langs->trans("FullList").'</a>';
  180. print '</tr>';
  181. $var = true;
  182. $i = 0;
  183. $staticaction=new ActionComm($db);
  184. $customerstatic=new Client($db);
  185. while ($i < $num)
  186. {
  187. $obj = $db->fetch_object($resql);
  188. $var=!$var;
  189. print '<tr '.$bc[$var].'>';
  190. $staticaction->type_code=$obj->code;
  191. $staticaction->libelle=$obj->label;
  192. $staticaction->id=$obj->id;
  193. print '<td>'.$staticaction->getNomUrl(1,34).'</td>';
  194. // print '<td>'.dol_trunc($obj->label,22).'</td>';
  195. print '<td>';
  196. if ($obj->rowid > 0)
  197. {
  198. $customerstatic->id=$obj->rowid;
  199. $customerstatic->name=$obj->sname;
  200. $customerstatic->client=$obj->client;
  201. print $customerstatic->getNomUrl(1,'',16);
  202. }
  203. print '</td>';
  204. $datep=$db->jdate($obj->dp);
  205. $datep2=$db->jdate($obj->dp2);
  206. // Date
  207. print '<td width="100" align="right">'.dol_print_date($datep,'day').'&nbsp;';
  208. $late=0;
  209. if ($obj->percent == 0 && $datep && $datep < time()) $late=1;
  210. if ($obj->percent == 0 && ! $datep && $datep2 && $datep2 < time()) $late=1;
  211. if ($obj->percent > 0 && $obj->percent < 100 && $datep2 && $datep2 < time()) $late=1;
  212. if ($obj->percent > 0 && $obj->percent < 100 && ! $datep2 && $datep && $datep < time()) $late=1;
  213. if ($late) print img_warning($langs->trans("Late"));
  214. print "</td>";
  215. // Statut
  216. print "<td align=\"right\" width=\"14\">".$staticaction->LibStatut($obj->percent,3)."</td>\n";
  217. print "</tr>\n";
  218. $i++;
  219. }
  220. print "</table><br>";
  221. $db->free($resql);
  222. }
  223. else
  224. {
  225. dol_print_error($db);
  226. }
  227. }
  228. /**
  229. * Show last actions array
  230. *
  231. * @param int $max Max nb of records
  232. * @return void
  233. */
  234. function show_array_last_actions_done($max=5)
  235. {
  236. global $langs, $conf, $user, $db, $bc, $socid;
  237. $now=dol_now();
  238. $sql = "SELECT a.id, a.percent, a.datep as da, a.datep2 as da2, a.fk_user_author, a.label,";
  239. $sql.= " c.code, c.libelle,";
  240. $sql.= " s.rowid, s.nom as sname, s.client";
  241. $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c LEFT JOIN ";
  242. $sql.= " ".MAIN_DB_PREFIX."actioncomm as a ON c.id = a.fk_action ";
  243. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  244. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  245. $sql.= " WHERE a.entity = ".$conf->entity;
  246. $sql.= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))";
  247. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  248. if ($socid) $sql.= " AND s.rowid = ".$socid;
  249. $sql .= " ORDER BY a.datep2 DESC";
  250. $sql .= $db->plimit($max, 0);
  251. $resql=$db->query($sql);
  252. if ($resql)
  253. {
  254. $num = $db->num_rows($resql);
  255. print '<table class="noborder" width="100%">';
  256. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastDoneTasks",$max).'</td>';
  257. print '<td colspan="2" align="right"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?status=done">'.$langs->trans("FullList").'</a>';
  258. print '</tr>';
  259. $var = true;
  260. $i = 0;
  261. $staticaction=new ActionComm($db);
  262. $customerstatic=new Societe($db);
  263. while ($i < $num)
  264. {
  265. $obj = $db->fetch_object($resql);
  266. $var=!$var;
  267. print '<tr '.$bc[$var].'>';
  268. $staticaction->type_code=$obj->code;
  269. $staticaction->libelle=$obj->label;
  270. $staticaction->id=$obj->id;
  271. print '<td>'.$staticaction->getNomUrl(1,34).'</td>';
  272. //print '<td>'.dol_trunc($obj->label,24).'</td>';
  273. print '<td>';
  274. if ($obj->rowid > 0)
  275. {
  276. $customerstatic->id=$obj->rowid;
  277. $customerstatic->name=$obj->sname;
  278. $customerstatic->client=$obj->client;
  279. print $customerstatic->getNomUrl(1,'',24);
  280. }
  281. print '</td>';
  282. // Date
  283. print '<td width="100" align="right">'.dol_print_date($db->jdate($obj->da2),'day');
  284. print "</td>";
  285. // Statut
  286. print "<td align=\"right\" width=\"14\">".$staticaction->LibStatut($obj->percent,3)."</td>\n";
  287. print "</tr>\n";
  288. $i++;
  289. }
  290. // TODO Ajouter rappel pour "il y a des contrats a mettre en service"
  291. // TODO Ajouter rappel pour "il y a des contrats qui arrivent a expiration"
  292. print "</table><br>";
  293. $db->free($resql);
  294. }
  295. else
  296. {
  297. dol_print_error($db);
  298. }
  299. }
  300. /**
  301. * Prepare array with list of tabs
  302. *
  303. * @return array Array of tabs to shoc
  304. */
  305. function agenda_prepare_head()
  306. {
  307. global $langs, $conf, $user;
  308. $h = 0;
  309. $head = array();
  310. $head[$h][0] = DOL_URL_ROOT."/admin/agenda.php";
  311. $head[$h][1] = $langs->trans("AutoActions");
  312. $head[$h][2] = 'autoactions';
  313. $h++;
  314. $head[$h][0] = DOL_URL_ROOT."/admin/agenda_xcal.php";
  315. $head[$h][1] = $langs->trans("ExportCal");
  316. $head[$h][2] = 'xcal';
  317. $h++;
  318. $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extsites.php";
  319. $head[$h][1] = $langs->trans("ExtSites");
  320. $head[$h][2] = 'extsites';
  321. $h++;
  322. $head[$h][0] = DOL_URL_ROOT."/admin/agenda_other.php";
  323. $head[$h][1] = $langs->trans("Other");
  324. $head[$h][2] = 'other';
  325. $h++;
  326. complete_head_from_modules($conf,$langs,null,$head,$h,'agenda_admin');
  327. $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extrafields.php";
  328. $head[$h][1] = $langs->trans("ExtraFields");
  329. $head[$h][2] = 'attributes';
  330. $h++;
  331. complete_head_from_modules($conf,$langs,null,$head,$h,'agenda_admin','remove');
  332. return $head;
  333. }
  334. /**
  335. * Prepare array with list of tabs
  336. *
  337. * @param object $object Object related to tabs
  338. * @return array Array of tabs to shoc
  339. */
  340. function actions_prepare_head($object)
  341. {
  342. global $langs, $conf, $user;
  343. $h = 0;
  344. $head = array();
  345. $head[$h][0] = DOL_URL_ROOT.'/comm/action/fiche.php?id='.$object->id;
  346. $head[$h][1] = $langs->trans("CardAction");
  347. $head[$h][2] = 'card';
  348. $h++;
  349. if (! empty($conf->global->AGENDA_USE_SEVERAL_CONTACTS))
  350. {
  351. $head[$h][0] = DOL_URL_ROOT.'/comm/action/contact.php?id='.$object->id;
  352. $head[$h][1] = $langs->trans("Contacts");
  353. $head[$h][2] = 'contact';
  354. $h++;
  355. }
  356. $head[$h][0] = DOL_URL_ROOT.'/comm/action/document.php?id='.$object->id;
  357. $head[$h][1] = $langs->trans('Documents');
  358. $head[$h][2] = 'documents';
  359. $h++;
  360. $head[$h][0] = DOL_URL_ROOT.'/comm/action/info.php?id='.$object->id;
  361. $head[$h][1] = $langs->trans('Info');
  362. $head[$h][2] = 'info';
  363. $h++;
  364. complete_head_from_modules($conf,$langs,$object,$head,$h,'action');
  365. complete_head_from_modules($conf,$langs,$object,$head,$h,'action','remove');
  366. return $head;
  367. }
  368. /**
  369. * Define head array for tabs of agenda setup pages
  370. *
  371. * @param string $param Parameters to add to url
  372. * @return array Array of head
  373. */
  374. function calendars_prepare_head($param)
  375. {
  376. global $langs, $conf, $user;
  377. $h = 0;
  378. $head = array();
  379. $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php'.($param?'?'.$param:'');
  380. $head[$h][1] = $langs->trans("Agenda");
  381. $head[$h][2] = 'card';
  382. $h++;
  383. $object=new stdClass();
  384. // Show more tabs from modules
  385. // Entries must be declared in modules descriptor with line
  386. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  387. // $this->tabs = array('entity:-tabname); to remove a tab
  388. complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda');
  389. complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda','remove');
  390. return $head;
  391. }