PageRenderTime 86ms CodeModel.GetById 25ms RepoModel.GetById 7ms app.codeStats 0ms

/htdocs/agenda/list.php

https://bitbucket.org/speedealing/speedealing
PHP | 341 lines | 263 code | 32 blank | 46 comment | 23 complexity | be3f88e3a7ae57b2cee83c665a9e6a5b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010-2012 Herve Prot <herve.prot@symeos.com>
  7. * Copyright (C) 2012 David Moothen <dmoothen@websitti.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php");
  24. require_once(DOL_DOCUMENT_ROOT . "/agenda/class/agenda.class.php");
  25. require_once(DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT . "/agenda/lib/agenda.lib.php");
  27. if (!empty($conf->projet->enabled))
  28. require_once(DOL_DOCUMENT_ROOT . "/core/lib/project.lib.php");
  29. $langs->load("companies");
  30. $langs->load("agenda");
  31. $langs->load("commercial");
  32. $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1;
  33. // Security check
  34. $socid = GETPOST("socid", 'alpha');
  35. if ($user->societe_id)
  36. $socid = $user->societe_id;
  37. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  38. $canedit = 1;
  39. if (!$user->rights->agenda->myactions->read)
  40. accessforbidden();
  41. if (!$user->rights->agenda->allactions->read)
  42. $canedit = 0;
  43. if (!$user->rights->agenda->allactions->read || $filter == 'mine') { // If no permission to see all, we show only affected to me
  44. $filtera = $user->id;
  45. $filtert = $user->id;
  46. $filterd = $user->id;
  47. }
  48. $type = GETPOST('type');
  49. $all = (GETPOST('all') && $user->rights->agenda->allactions->read);
  50. $object = new Agenda($db);
  51. if (!empty($_GET['json'])) {
  52. $output = array(
  53. "sEcho" => intval($_GET['sEcho']),
  54. "iTotalRecords" => 0,
  55. "iTotalDisplayRecords" => 0,
  56. "aaData" => array()
  57. );
  58. $keystart[0] = $user->id;
  59. $keyend[0] = $user->id;
  60. $keyend[1] = new stdClass();
  61. /* $params = array('startkey' => array($user->id, mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"))),
  62. 'endkey' => array($user->id, mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")))); */
  63. try {
  64. $result = $object->getView($_GET["json"], array('startkey' => $keystart, 'endkey' => $keyend));
  65. } catch (Exception $exc) {
  66. print $exc->getMessage();
  67. }
  68. $iTotal = count($result->rows);
  69. $output["iTotalRecords"] = $iTotal;
  70. $output["iTotalDisplayRecords"] = $iTotal;
  71. $i = 0;
  72. foreach ($result->rows as $aRow) {
  73. $output["aaData"][] = $aRow->value;
  74. }
  75. header('Content-type: application/json');
  76. echo json_encode($output);
  77. exit;
  78. }
  79. $contact = new Contact($db);
  80. $societe = new Societe($db);
  81. $societestatic = new Societe($db);
  82. $userstatic = new User($db);
  83. /*
  84. * Actions
  85. */
  86. /*
  87. * View
  88. */
  89. $now = dol_now();
  90. llxHeader('', $langs->trans("Agenda"));
  91. $title = $langs->trans("DoneAndToDoActions");
  92. if ($type == 'DONE')
  93. $title = $langs->trans("DoneActions");
  94. if ($type == 'TOTO')
  95. $title = $langs->trans("ToDoActions");
  96. if ($socid) {
  97. $societe = new Societe($db);
  98. $societe->fetch($socid);
  99. $newtitle = $langs->trans($title) . ' ' . $langs->trans("For") . ' ' . $societe->name;
  100. } else {
  101. $newtitle = $langs->trans($title);
  102. }
  103. print_fiche_titre($newtitle);
  104. ?>
  105. <div class="dashboard">
  106. <div class="columns">
  107. <div class="nine-columns twelve-columns-mobile graph">
  108. <?php echo $object->graphEisenhower(); ?>
  109. </div>
  110. <div class="three-columns twelve-columns-mobile new-row-mobile">
  111. <ul class="stats split-on-mobile">
  112. <li>
  113. <?php
  114. $agenda = new Agenda($db);
  115. $result = $agenda->getView("countTODO", array("group" => true, "key" => $user->id));
  116. print '<strong>' . (int) $result->rows[0]->value . '</strong>';
  117. print $langs->trans('NewActions');
  118. ?>
  119. </li>
  120. <li>
  121. <?php
  122. $result = $agenda->getView("countON", array("group" => true, "key" => $user->id));
  123. print '<strong>' . (int) $result->rows[0]->value . '</strong>';
  124. print $langs->trans('DoActions');
  125. ?>
  126. </li>
  127. <li><?php
  128. $result = $agenda->getView("countByUser", array("group" => true, "group_level" => "none", "startkey" => array($user->id, date("c",mktime(0, 0, 0, 1, 1, date(Y)))), "endkey" => array($user->id, new stdClass())));
  129. print '<strong>' . (int) $result->rows[0]->value . '</strong>';
  130. print $langs->trans('SumMyActions');
  131. ?>
  132. </li>
  133. <li>
  134. <?php
  135. $result = $agenda->getView("count", array("group" => true, "group_level" => "none", "startkey" => date("c",mktime(0, 0, 0, 1, 1, date(Y))), "endkey" => new stdClass()));
  136. print '<strong>' . (int) $result->rows[0]->value . '</strong>';
  137. print $langs->trans('SumActions');
  138. ?>
  139. </li>
  140. </ul>
  141. </div>
  142. </div>
  143. </div>
  144. <?php
  145. print '<div class="with-padding">';
  146. /*
  147. * Barre d'actions
  148. *
  149. */
  150. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  151. print '<p class="button-height right">';
  152. print '<span class="button-group">';
  153. print '<a class="button icon-star" href="' . strtolower(get_class($object)) . '/fiche.php?action=create">' . $langs->trans("NewAction") . '</a>';
  154. print "</span>";
  155. print "</p>";
  156. }
  157. $i = 0;
  158. $obj = new stdClass();
  159. print '<table class="display dt_act" id="listactions" >';
  160. // Ligne des titres
  161. print'<thead>';
  162. print'<tr>';
  163. print'<th>';
  164. print'</th>';
  165. $obj->aoColumns[$i] = new stdClass();
  166. $obj->aoColumns[$i]->mDataProp = "_id";
  167. $obj->aoColumns[$i]->bUseRendered = false;
  168. $obj->aoColumns[$i]->bSearchable = false;
  169. $obj->aoColumns[$i]->bVisible = false;
  170. $i++;
  171. print'<th class="essential">';
  172. print $langs->trans("Titre");
  173. print'</th>';
  174. $obj->aoColumns[$i] = new stdClass();
  175. $obj->aoColumns[$i]->mDataProp = "label";
  176. $obj->aoColumns[$i]->bUseRendered = false;
  177. $obj->aoColumns[$i]->bSearchable = true;
  178. $obj->aoColumns[$i]->sDefaultContent = "";
  179. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("label", "url");
  180. $i++;
  181. print'<th class="essential">';
  182. print $langs->trans('DateEchAction');
  183. print'</th>';
  184. $obj->aoColumns[$i] = new stdClass();
  185. $obj->aoColumns[$i]->mDataProp = "datep";
  186. $obj->aoColumns[$i]->sClass = "center";
  187. $obj->aoColumns[$i]->sDefaultContent = "";
  188. $obj->aoColumns[$i]->sType = "date";
  189. $obj->aoColumns[$i]->bUseRendered = false;
  190. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("datep", "datetime");
  191. //$obj->aoColumns[$i]->sClass = "edit";
  192. $i++;
  193. print'<th class="essential">';
  194. print $langs->trans('Company');
  195. print'</th>';
  196. $obj->aoColumns[$i] = new stdClass();
  197. $obj->aoColumns[$i]->mDataProp = "societe.name";
  198. $obj->aoColumns[$i]->sDefaultContent = "";
  199. $obj->aoColumns[$i]->fnRender = $societe->datatablesFnRender("societe.name", "url", array('id' => "societe.id"));
  200. $i++;
  201. print'<th class="essential">';
  202. print $langs->trans('Contact');
  203. print'</th>';
  204. $obj->aoColumns[$i] = new stdClass();
  205. $obj->aoColumns[$i]->mDataProp = "contact.name";
  206. $obj->aoColumns[$i]->sDefaultContent = "";
  207. $obj->aoColumns[$i]->fnRender = $contact->datatablesFnRender("contact.name", "url", array('id' => "contact.id"));
  208. $i++;
  209. /* print'<th class="essential">';
  210. print $langs->trans('ActionUserAsk');
  211. print'</th>';
  212. $obj->aoColumns[$i]->mDataProp = "author";
  213. $obj->aoColumns[$i]->sDefaultContent = "";
  214. $obj->aoColumns[$i]->fnRender = $userstatic->datatablesFnRender("author.name", "url", array('id' => "author.id"));
  215. $i++; */
  216. print'<th class="essential">';
  217. print $langs->trans('AffectedTo');
  218. print'</th>';
  219. $obj->aoColumns[$i] = new stdClass();
  220. $obj->aoColumns[$i]->mDataProp = "usertodo";
  221. $obj->aoColumns[$i]->sClass = "dol_select";
  222. $obj->aoColumns[$i]->sDefaultContent = "";
  223. $obj->aoColumns[$i]->fnRender = $userstatic->datatablesFnRender("usertodo.name", "url", array('id' => "usertodo.id"));
  224. $i++;
  225. print'<th class="essential">';
  226. print $langs->trans('DoneBy');
  227. print'</th>';
  228. $obj->aoColumns[$i] = new stdClass();
  229. $obj->aoColumns[$i]->mDataProp = "userdone";
  230. $obj->aoColumns[$i]->sDefaultContent = "";
  231. $obj->aoColumns[$i]->fnRender = $userstatic->datatablesFnRender("userdone.name", "url", array('id' => "userdone.id"));
  232. $i++;
  233. print'<th class="essential">';
  234. print $langs->trans("Status");
  235. print'</th>';
  236. $obj->aoColumns[$i] = new stdClass();
  237. $obj->aoColumns[$i]->mDataProp = "Status";
  238. $obj->aoColumns[$i]->sClass = "center";
  239. $obj->aoColumns[$i]->sDefaultContent = "TODO";
  240. $obj->aoColumns[$i]->fnRender = $object->datatablesFnRender("Status", "status", array("dateEnd" => "datep"));
  241. $i++;
  242. print'<th class="essential">';
  243. print $langs->trans('Action');
  244. print'</th>';
  245. $obj->aoColumns[$i] = new stdClass();
  246. $obj->aoColumns[$i]->mDataProp = "";
  247. $obj->aoColumns[$i]->sClass = "center content_actions";
  248. $obj->aoColumns[$i]->sWidth = "60px";
  249. $obj->aoColumns[$i]->bSortable = false;
  250. $obj->aoColumns[$i]->sDefaultContent = "";
  251. $url = "agenda/fiche.php";
  252. $obj->aoColumns[$i]->fnRender = 'function(obj) {
  253. var ar = [];
  254. ar[ar.length] = "<a href=\"' . $url . '?id=";
  255. ar[ar.length] = obj.aData._id.toString();
  256. ar[ar.length] = "&action=edit&backtopage=' . $_SERVER['PHP_SELF'] . '\" class=\"sepV_a\" title=\"' . $langs->trans("Edit") . '\"><img src=\"' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/edit.png\" alt=\"\" /></a>";
  257. ar[ar.length] = "<a href=\"\"";
  258. ar[ar.length] = " class=\"delEnqBtn\" title=\"' . $langs->trans("Delete") . '\"><img src=\"' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/delete.png\" alt=\"\" /></a>";
  259. var str = ar.join("");
  260. return str;
  261. }';
  262. print'</tr>';
  263. print'</thead>';
  264. print'<tfoot>';
  265. /* input search view */
  266. $i = 0; //Doesn't work with bServerSide
  267. print'<tr>';
  268. print'<th id="' . $i . '"></th>';
  269. $i++;
  270. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Name") . '" /></th>';
  271. $i++;
  272. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Date") . '" /></th>';
  273. $i++;
  274. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Company") . '" /></th>';
  275. $i++;
  276. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Contact") . '" /></th>';
  277. $i++;
  278. /* print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search author") . '" /></th>';
  279. $i++; */
  280. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search usertodo") . '" /></th>';
  281. $i++;
  282. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search userdone") . '" /></th>';
  283. $i++;
  284. print'<th id="' . $i . '"><input type="text" placeholder="' . $langs->trans("Search Status") . '" /></th>';
  285. $i++;
  286. print'<th id="' . $i . '"></th>';
  287. $i++;
  288. print'</tr>';
  289. print'</tfoot>';
  290. print'<tbody>';
  291. print'</tbody>';
  292. print "</table>";
  293. $obj->aaSorting = array(array(2, 'asc'));
  294. //$obj->bServerSide = true;
  295. if ($all) {
  296. if ($type == "DONE")
  297. $obj->sAjaxSource = "core/ajax/listdatatables.php?json=listDONEByUser&class=" . get_class($object);
  298. else
  299. $obj->sAjaxSource = "core/ajax/listdatatables.php?json=listTODOByUser&class=" . get_class($object);
  300. } else {
  301. if ($type == "DONE")
  302. $obj->sAjaxSource = $_SERVER["PHP_SELF"] . "?json=listDONEByUser";
  303. else
  304. $obj->sAjaxSource = $_SERVER["PHP_SELF"] . "?json=listTODOByUser";
  305. }
  306. $object->datatablesCreate($obj, "listactions", true, true);
  307. print '</div>'; // end
  308. llxFooter();
  309. ?>