PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 5ms app.codeStats 0ms

/core/web/includes/PageGenerator.php

https://github.com/vmasilva/mmc
PHP | 2653 lines | 1868 code | 271 blank | 514 comment | 255 complexity | a01120f2c9a1486fc1cd1071a8463751 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * (c) 2004-2007 Linbox / Free&ALter Soft, http://linbox.com
  4. * (c) 2007-2010 Mandriva, http://www.mandriva.com
  5. *
  6. * $Id$
  7. *
  8. * This file is part of Mandriva Management Console (MMC).
  9. *
  10. * MMC is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * MMC is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with MMC. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. require ("FormGenerator.php");
  24. /**
  25. * return an uniqId (use full for javascript auto generation
  26. */
  27. function getUniqId() {
  28. global $__uniqID;
  29. $__uniqID++;
  30. return $__uniqID;
  31. }
  32. /**
  33. * can echo obj and string with the same function
  34. * similar to "echo" in PHP5
  35. */
  36. function echo_obj($obj) {
  37. if (is_object($obj)){
  38. echo $obj->__toString();
  39. }
  40. else if(is_bool($obj)) {
  41. if($obj)
  42. echo '<img src="img/common/icn_yes.gif" alt="yes" />';
  43. }
  44. else {
  45. echo ($obj);
  46. }
  47. }
  48. /**
  49. * class for action encapsulation
  50. * Abstract class for the moment
  51. * @see EditInPlace
  52. */
  53. class ActionEncapsulator {
  54. function ActionEncapsulator() {
  55. }
  56. function __toString() {
  57. return "default action encapsulator";
  58. }
  59. }
  60. /**
  61. * AutoGenerate an EditInPlace text
  62. * based on scriptaculous javascript
  63. */
  64. class EditInPlace extends ActionEncapsulator{
  65. var $origText;
  66. var $url;
  67. var $param;
  68. function EditInPlace($origText,$url,$param) {
  69. $this->origText = $origText;
  70. $this->url = $url;
  71. $this->param = $param;
  72. }
  73. function __toString() {
  74. $param = array();
  75. foreach ($this->param as $key=>$value) {
  76. $param[] = "$key=$value";
  77. }
  78. $urlparam = implode("&",$param);
  79. if ($this->origText== '') {
  80. $this->origText= "n/a";
  81. }
  82. $idx = getUniqId();
  83. $str = '';
  84. $str.= "<span id=\"id$idx\" class=\"editinplace\">".$this->origText."</span>";
  85. $str .= '<script type="text/javascript">';
  86. $str .= " new Ajax.InPlaceEditor($('id$idx'),'".$this->url."', {\n
  87. okButton: true, cancelLink: true, cancelText : '"._('Cancel')."',
  88. highlightcolor : '#FF9966',
  89. ajaxOptions: {method: 'get' },\n
  90. callback: function(form,value) {\n
  91. return '$urlparam&value='+value\n
  92. }\n
  93. });\n
  94. </script>\n";
  95. return $str;
  96. }
  97. }
  98. /**
  99. * class for action in various application
  100. */
  101. class ActionItem {
  102. var $desc;
  103. var $action;
  104. var $classCss;
  105. var $paramString;
  106. var $mod;
  107. /**
  108. * Constructor
  109. * @param $desc description
  110. * @param $action string include in the url
  111. * @param $classCss class for CSS like "supprimer" or other class define
  112. * in the CSS global.css
  113. * @param $paramString add "&$param=" at the very end of the url
  114. */
  115. function ActionItem($desc, $action, $classCss, $paramString, $module = null, $submod = null, $tab = null, $mod = false) {
  116. $this->desc=$desc;
  117. $this->action=$action;
  118. $this->classCss=$classCss;
  119. $this->paramString=$paramString;
  120. if ($module == null) $this->module = $_GET["module"];
  121. else $this->module = $module;
  122. if ($submod == null) $this->submod = $_GET["submod"];
  123. else $this->submod = $submod;
  124. $this->tab = $tab;
  125. $this->mod = $mod;
  126. $this->path = $this->module . "/" . $this->submod . "/" . $this->action;
  127. if ($this->tab != null) {
  128. $this->path .= "/" . $this->tab;
  129. }
  130. }
  131. /**
  132. * display a link for the action
  133. * @param add &$this->param=$param at the very end of the url
  134. * display "displayWithRight" if you have correct right
  135. */
  136. function display($param, $extraParams = array()) {
  137. if (hasCorrectAcl($this->module,$this->submod,$this->action)) {
  138. $this->displayWithRight($param, $extraParams);
  139. } else {
  140. $this->displayWithNoRight($param, $extraParams);
  141. }
  142. }
  143. /**
  144. * display function if you have correct right on this action
  145. */
  146. function displayWithRight($param, $extraParams = array()) {
  147. /* add special param for actionItem */
  148. if (is_array($extraParams)) {
  149. $extraParams['mod'] = $this->mod;
  150. }
  151. echo "<li class=\"".$this->classCss."\">";
  152. if (is_array($extraParams) & !empty($extraParams)) $urlChunk = $this->buildUrlChunk($extraParams);
  153. else $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($extraParams);
  154. echo "<a title=\"".$this->desc."\" href=\"" . urlStr($this->path) . $urlChunk . "\">&nbsp;</a>";
  155. echo "</li>";
  156. }
  157. /**
  158. * display function if you don't have the right for this action
  159. */
  160. function displayWithNoRight($param, $extraParams = array()) {
  161. echo "<li class=\"".$this->classCss."\" style=\"opacity: 0.30;\">";
  162. echo "<a title=\"".$this->desc."\" href=\"#\" onclick='return false;'>&nbsp;</a>";
  163. echo "</li>";
  164. }
  165. /**
  166. * transform $obj param in link for this action
  167. */
  168. function encapsulate($obj, $extraParams = Array()) {
  169. if (hasCorrectAcl($this->module,$this->submod,$this->action)) {
  170. if (is_array($extraParams) & !empty($extraParams)) {
  171. $urlChunk = $this->buildUrlChunk($extraParams);
  172. } else {
  173. $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($obj);
  174. }
  175. $str= "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk ."\">";
  176. $str.= trim($obj);
  177. $str.= "</a>";
  178. return $str;
  179. } else {
  180. $str= "<a title=\"".$this->desc."\" href=\"#\">";
  181. $str.= "$obj";
  182. $str.=" </a>";
  183. return $str;
  184. }
  185. }
  186. /**
  187. * Build an URL chunk using a array of option => value
  188. */
  189. function buildUrlChunk($arr) {
  190. $urlChunk = "";
  191. foreach($arr as $option => $value) {
  192. $urlChunk .= "&amp;" . $option . "=" . urlencode($value);
  193. }
  194. return $urlChunk;
  195. }
  196. /**
  197. * display help (not use for the moment)
  198. */
  199. function strHelp() {
  200. $str = "";
  201. $str.= "<li class=\"".$this->classCss."\">";
  202. $str.= "<a title=\"".$this->desc."\" href=\"#\">";
  203. $str.= " </a>".$this->desc."</li>";
  204. return $str;
  205. }
  206. }
  207. /**
  208. * display action in a JavaScript popup
  209. *
  210. * @see ActionItem
  211. * @see showPopup (js)
  212. */
  213. class ActionPopupItem extends ActionItem {
  214. function ActionPopupItem($desc, $action, $classCss, $paramString, $module = null, $submod = null, $tab = null, $width = 300, $mod = false) {
  215. $this->ActionItem($desc, $action, $classCss, $paramString, $module, $submod, $tab, $mod);
  216. $this->setWidth($width);
  217. }
  218. /**
  219. * Set the JavaScript popup width.
  220. * The default width value is 300px.
  221. */
  222. function setWidth($width) {
  223. $this->width = $width;
  224. }
  225. function displayWithRight($param, $extraParams = array()) {
  226. /* Add special param for actionPopupItem */
  227. $extraParams['mod'] = $this->mod;
  228. if (is_array($extraParams) & !empty($extraParams)) {
  229. $urlChunk = $this->buildUrlChunk($extraParams);
  230. } else {
  231. $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($param);
  232. }
  233. echo "<li class=\"".$this->classCss."\">";
  234. echo "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=" . $this->action . $urlChunk . "\"";
  235. echo " onclick=\"PopupWindow(event,'main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=" .$this->action . $urlChunk . "', " . $this->width . "); return false;\">&nbsp;</a>";
  236. echo "</li>";
  237. }
  238. function encapsulate($obj, $extraParams = array()) {
  239. if (is_array($extraParams) & !empty($extraParams)) {
  240. $urlChunk = $this->buildUrlChunk($extraParams);
  241. } else {
  242. $urlChunk = "&amp;" . $this->paramString."=" . rawurlencode($obj);
  243. }
  244. $str= "<a title=\"".$this->desc."\" href=\"main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk . "\" ";
  245. $str.= " onclick=\"showPopup(event,'main.php?module=".$this->module."&amp;submod=".$this->submod."&amp;action=".$this->action . $urlChunk . "', " . $this->width . "); return false;\">";
  246. $str.= "$obj";
  247. $str.=" </a>";
  248. return $str;
  249. }
  250. }
  251. class EmptyActionItem extends ActionItem {
  252. function EmptyActionItem() {
  253. }
  254. function display($param = null) {
  255. print '<li class="empty"><a href="#" onclick="return false;">&nbsp;</a></li>';
  256. }
  257. }
  258. /**
  259. * class who maintain array presentation of information
  260. */
  261. class ListInfos extends HtmlElement {
  262. var $arrInfo; /**< main list */
  263. var $extraInfo;
  264. var $paramInfo;
  265. var $name;
  266. var $arrAction; /**< list of possible action */
  267. var $end, $start;
  268. var $description; /**< list of description (not an obligation) */
  269. var $col_width; /**< Contains the columns width */
  270. var $tooltip; /**< Contains the tooltip for column label */
  271. /**
  272. * constructor
  273. * @param $tab must be an array of array
  274. */
  275. function ListInfos($tab, $description ="", $extranavbar = "") {
  276. $this->arrInfo=$tab;
  277. $this->arrAction=array();
  278. $this->description[] = $description;
  279. $this->extranavbar = $extranavbar;
  280. $this->initVar();
  281. $this->col_width = array();
  282. $this->tooltip = array();
  283. $this->tooltip[] = "";
  284. $this->firstColumnActionLink = True;
  285. $this->_addInfo = array();
  286. }
  287. function setAdditionalInfo($addinfo) {
  288. $this->_addInfo = $addinfo;
  289. }
  290. /**
  291. * Set the number of rows to display per ListInfos page.
  292. * It overrides the default value defined by $conf["global"]["maxperpage"].
  293. *
  294. * @param $value The number of rows
  295. */
  296. function setRowsPerPage($value) {
  297. $this->end = $value;
  298. }
  299. /**
  300. * add an ActionItem
  301. * @param $objActionItem object ActionItem
  302. */
  303. function addActionItem($objActionItem) {
  304. $this->arrAction[] = &$objActionItem;
  305. }
  306. /**
  307. * Add an array of ActionItem
  308. * Useful if all action items are not the same for each row of the list
  309. *
  310. */
  311. function addActionItemArray($objActionItemArray) {
  312. assert(is_array($objActionItemArray));
  313. $this->arrAction[] = &$objActionItemArray;
  314. }
  315. /**
  316. * add an array String to display
  317. * @param $arrString an Array String to display
  318. * @param description Table column name
  319. * @param width Table column width
  320. * @param tooltip Tooltip to display on the column name
  321. */
  322. function addExtraInfo($arrString, $description= "", $width="", $tooltip = "") {
  323. assert(is_array($arrString));
  324. $this->extraInfo[] = &$arrString;
  325. $this->description[] = $description;
  326. $this->col_width[] = $width;
  327. $this->tooltip[] = $tooltip;
  328. }
  329. /**
  330. * set parameters array for main action
  331. * @param $arrString an Array of string to be used as parameters for the main action
  332. */
  333. function setParamInfo($arrString) {
  334. assert(is_array($arrString));
  335. $this->paramInfo = $arrString;
  336. }
  337. /**
  338. * Set the left padding of the table header.
  339. * It will be set to 32 by default
  340. * @param $padding an integer
  341. */
  342. function setTableHeaderPadding($padding) {
  343. $this->first_elt_padding = $padding;
  344. }
  345. /**
  346. * Disable the link to the first available action in the table
  347. * This link is always done by default
  348. */
  349. function disableFirstColumnActionLink() {
  350. $this->firstColumnActionLink = False;
  351. }
  352. /**
  353. * init class' vars
  354. */
  355. function initVar() {
  356. $this->name="Elements";
  357. global $conf;
  358. $this->maxperpage = (isset($_REQUEST['maxperpage'])) ? $_REQUEST['maxperpage'] : $conf['global']['maxperpage'];
  359. if (!isset($_GET["start"])) {
  360. if (!isset($_POST["start"])) {
  361. $this->start = 0;
  362. if (count($this->arrInfo) > 0) {
  363. $this->end = $this->maxperpage - 1;
  364. } else {
  365. $this->end = 0;
  366. }
  367. }
  368. } else {
  369. $this->start = $_GET["start"];
  370. $this->end = $_GET["end"];
  371. }
  372. /* Set a basic navigation bar */
  373. $this->setNavBar(new SimpleNavBar($this->start, $this->end, count($this->arrInfo), $this->extranavbar));
  374. }
  375. /**
  376. * set the name of the array (for CSS)
  377. */
  378. function setName($name) {
  379. $this->name=$name;
  380. }
  381. /**
  382. * set the cssclass of a row
  383. */
  384. function setCssClass($name) {
  385. $this->cssClass=$name;
  386. }
  387. /**
  388. * set a cssclass for each row
  389. */
  390. function setCssClasses($a_names) {
  391. $this->cssClasses = $a_names;
  392. }
  393. /**
  394. * Set the ListInfos navigation bar
  395. */
  396. function setNavBar($navbar) {
  397. $this->navbar = $navbar;
  398. }
  399. /**
  400. *
  401. * Display the widget navigation bar if $navbar is True
  402. *
  403. * @param $navbar: if $navbar is true the navigation bar is displayed
  404. */
  405. function displayNavbar($navbar) {
  406. if ($navbar) $this->navbar->display();
  407. }
  408. /**
  409. * draw number of page etc...
  410. */
  411. function drawHeader($navbar = 1) {
  412. $this->displayNavbar($navbar);
  413. echo "<p class=\"listInfos\">";
  414. /*
  415. * Management of the numbers "start" and "end" to display depending on the maxperpage set in the selector
  416. * These numbers are more user-friendly and do not begin with 0
  417. */
  418. echo $this->name." <strong>".min($this->start + 1, count($this->arrInfo)) . "</strong>\n ";
  419. echo _("to")." <strong>".min($this->end + 1, count($this->arrInfo))."</strong>\n";
  420. printf (_(" - Total <b>%s </b>")."\n",count($this->arrInfo));
  421. /* Display page counter only when possible */
  422. if ($this->maxperpage >= ($this->end - $this->start)) {
  423. echo "("._("page")." ";
  424. printf("%.0f", ($this->end + 1) / $this->maxperpage);
  425. echo " / ";
  426. $pages = intval((count($this->arrInfo) / $this->maxperpage)) ;
  427. if ((count($this->arrInfo) % $this->maxperpage > 0) && (count($this->arrInfo) > $this->maxperpage))
  428. $pages++;
  429. else if ((count($this->arrInfo) > 0) && ($pages < 1))
  430. $pages = 1;
  431. else if ($pages < 0)
  432. $pages = 0;
  433. printf("%.0f", $pages);
  434. echo ")\n";
  435. }
  436. echo "</p>";
  437. }
  438. /**
  439. * display main action (first action
  440. */
  441. function drawMainAction($idx) {
  442. if (!empty($this->cssClass)) {
  443. echo "<td class=\"".$this->cssClass."\">";
  444. } else {
  445. echo "<td>";
  446. }
  447. if (is_a($this->arrAction[0], 'ActionItem')) {
  448. $firstAction = $this->arrAction[0];
  449. } else if (is_array($this->arrAction[0])) {
  450. $firstAction = $this->arrAction[0][$idx];
  451. }
  452. echo $firstAction->encapsulate($this->arrInfo[$idx], $this->paramInfo[$idx]);
  453. if (isset($this->_addInfo[$idx])) {
  454. print " " . $this->_addInfo[$idx];
  455. }
  456. echo "</td>";
  457. }
  458. function drawTable($navbar = 1) {
  459. echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" class=\"listinfos\">\n";
  460. echo "<thead><tr>";
  461. $first = False;
  462. foreach ($this->description as $key => $desc) {
  463. if (isset($this->col_width[$key])) {
  464. $width_styl = 'width: '.$this->col_width[$key].';';
  465. } else {
  466. $width_styl = '';
  467. }
  468. if (!$first) {
  469. if (!isset($this->first_elt_padding)) {
  470. $this->first_elt_padding = 32;
  471. }
  472. echo "<td style=\"$width_styl\"><span style=\"color: #777; padding-left: ".$this->first_elt_padding."px;\">$desc</span></td>";
  473. $first = True;
  474. } else {
  475. /* Draw table header line */
  476. /* Add a tooltip to the column name if there is one set */
  477. if (!empty($this->tooltip[$key])) {
  478. $tooltipbegin = "<a href=\"#\" class=\"tooltip\">";
  479. $tooltipend = "<span>" . $this->tooltip[$key] . "</span></a>";
  480. } else {
  481. $tooltipbegin = "";
  482. $tooltipend = "";
  483. }
  484. echo "<td style=\"$width_styl\"><span style=\"color: #777;\">$tooltipbegin$desc$tooltipend</span></td>";
  485. }
  486. }
  487. if (count($this->arrAction)!=0) { //if we have actions
  488. if (!empty($this->col_width)) {
  489. $width_styl = $this->col_width[count($this->col_width) - 1];
  490. }
  491. $width_styl = isset($width_styl) ? sprintf('width: %s;', $width_styl) : '';
  492. echo "<td style=\"text-align: right; $width_styl\"><span style=\"color: #AAA;\" >Actions</span></td>";
  493. }
  494. echo "</tr></thead>";
  495. for ( $idx = $this->start; ($idx < count($this->arrInfo)) && ($idx <= $this->end); $idx++) {
  496. if (($this->start - $idx) % 2) {
  497. echo "<tr";
  498. if (!empty($this->cssClasses[$idx])) {
  499. echo " class=\"".$this->cssClasses[$idx]."\"";
  500. }
  501. echo ">";
  502. } else {
  503. echo "<tr class=\"alternate";
  504. if (!empty($this->cssClasses[$idx])) {
  505. echo " ".$this->cssClasses[$idx];
  506. }
  507. echo "\">";
  508. }
  509. //link to first action (if we have an action)
  510. if (count($this->arrAction) && $this->firstColumnActionLink) {
  511. $this->drawMainAction($idx);
  512. } else {
  513. if (!empty($this->cssClass)) {
  514. echo "<td class=\"".$this->cssClass."\">";
  515. } else {
  516. echo "<td>";
  517. }
  518. echo $this->arrInfo[$idx];
  519. echo "</td>";
  520. }
  521. if ($this->extraInfo)
  522. foreach ($this->extraInfo as $arrayTMP) {
  523. echo "<td>";
  524. if(trim($arrayTMP[$idx]) != "") {
  525. echo_obj($arrayTMP[$idx]);
  526. }
  527. else {
  528. echo "&nbsp;";
  529. }
  530. echo "</td>";
  531. }
  532. if (count($this->arrAction)!=0) {
  533. echo "<td class=\"action\">";
  534. echo "<ul class=\"action\">";
  535. foreach ($this->arrAction as $objActionItem) {
  536. if (is_a($objActionItem, 'ActionItem')) {
  537. $objActionItem->display($this->arrInfo[$idx], $this->paramInfo[$idx]);
  538. } else if (is_array($objActionItem)) {
  539. $obj = $objActionItem[$idx];
  540. $obj->display($this->arrInfo[$idx], $this->paramInfo[$idx]);
  541. }
  542. }
  543. echo "</ul>";
  544. echo "</td>";
  545. }
  546. echo "</tr>\n";
  547. }
  548. echo "</table>\n";
  549. $this->displayNavbar($navbar);
  550. if (false) {
  551. /* Code disabled because not used and make javavascript errors */
  552. print '<script type="text/javascript"><!--';
  553. print '$(\'help\').innerHTML=\'\''."\n";
  554. print '$(\'help\').innerHTML+=\'<ul>\''."\n";
  555. print '$(\'help\').innerHTML+=\'<li><h3>Aide contextuelle</h3></li>\''."\n";
  556. foreach ($this->arrAction as $objActionItem) {
  557. $content = $objActionItem->strHelp();
  558. print '$(\'help\').innerHTML+=\''.$content.'\';'."\n";
  559. }
  560. print '$(\'help\').innerHTML+=\'</ul>\''."\n";
  561. print '--></script>';
  562. }
  563. }
  564. function display($navbar = 1, $header =1 ) {
  565. if (!isset($this->paramInfo)) {
  566. $this->paramInfo = $this->arrInfo;
  567. }
  568. if ($header == 1) {
  569. $this->drawHeader($navbar);
  570. }
  571. $n = new NotifyWidget();
  572. if (isset($_SESSION['__notify'])) {
  573. $n->showJS();
  574. }
  575. $this->drawTable($navbar);
  576. }
  577. }
  578. /**
  579. * A modified version of Listinfos
  580. */
  581. class OptimizedListInfos extends ListInfos {
  582. /**
  583. * Allow to set another item count
  584. */
  585. function setItemCount($count) {
  586. $this->itemCount = $count;
  587. }
  588. function getItemCount() {
  589. return $this->itemCount;
  590. }
  591. /**
  592. * init class' vars
  593. */
  594. function initVar() {
  595. $this->name="Elements";
  596. global $conf;
  597. if (!isset($_GET["start"])) {
  598. if (!isset($_POST["start"])) {
  599. $this->start = 0;
  600. if (count($this->arrInfo) > 0) {
  601. $this->end = (isset($_REQUEST['maxperpage'])) ? ($_REQUEST['maxperpage'] - 1) : ($conf["global"]["maxperpage"] - 1);
  602. } else {
  603. $this->end = 0;
  604. }
  605. }
  606. } else {
  607. $this->start = $_GET["start"];
  608. $this->end = $_GET["end"];
  609. }
  610. $this->maxperpage = (isset($_REQUEST['maxperpage'])) ? $_REQUEST['maxperpage'] : $conf["global"]["maxperpage"];
  611. $this->setItemCount(count($this->arrInfo));
  612. $this->startreal = $this->start;
  613. $this->endreal = $this->end;
  614. }
  615. /**
  616. * draw number of page etc...
  617. */
  618. function drawHeader($navbar=1) {
  619. $count = $this->getItemCount();
  620. $this->displayNavbar($navbar);
  621. echo "<p class=\"listInfos\">";
  622. /*
  623. * Management of the numbers "start" and "end" to display depending on the maxperpage set in the selector
  624. * These numbers are more user-friendly and do not begin with 0
  625. */
  626. echo $this->name." <strong>".min($this->startreal + 1, $count) . "</strong>\n ";
  627. echo _("to")." <strong>".min($this->endreal + 1, $count)."</strong>\n";
  628. printf (_(" - Total <b>%s </b>")."\n", $count);
  629. /* Display page counter only when possible */
  630. if ($this->maxperpage >= ($this->endreal - $this->startreal)) {
  631. echo "("._("page")." ";
  632. printf("%.0f", ($this->endreal + 1) / $this->maxperpage);
  633. echo " / ";
  634. $pages = intval(($count / $this->maxperpage)) ;
  635. if (($count % $this->maxperpage > 0) && ($count > $this->maxperpage))
  636. $pages++;
  637. else if (($count > 0) && ($pages < 1))
  638. $pages = 1;
  639. else if ($pages < 0)
  640. $pages = 0;
  641. printf("%.0f", $pages);
  642. echo ")\n";
  643. }
  644. echo "</p>";
  645. }
  646. }
  647. /**
  648. * specific class for UserDisplay
  649. */
  650. class UserInfos extends OptimizedListInfos {
  651. var $css = array(); //css for first column
  652. function drawMainAction($idx) {
  653. echo "<td class=\"".$this->css[$idx]."\">";
  654. echo $this->arrAction[0]->encapsulate($this->arrInfo[$idx], $this->paramInfo[$idx]);
  655. echo "</td>";
  656. }
  657. }
  658. /**
  659. *
  660. * Display a previous/next navigation bar for ListInfos widget
  661. *
  662. */
  663. class SimpleNavBar extends HtmlElement {
  664. /**
  665. * @param $curstart: the first item index to display
  666. * @param $curent: the last item index
  667. * @param $itemcount: total number of item
  668. * @param $filter: the current list filter
  669. * @param $max: max quantity of elements in a page
  670. * @param $paginator: boolean which enable the selector of the number of results in a page
  671. */
  672. function SimpleNavBar($curstart, $curend, $itemcount, $extra = "", $max = "", $paginator = false) {
  673. global $conf;
  674. if(isset($max) && $max != "") {
  675. $this->max = $max;
  676. } else {
  677. $this->max = $conf["global"]["maxperpage"];
  678. }
  679. $this->curstart = $curstart;
  680. $this->curend = $curend;
  681. $this->itemcount = $itemcount;
  682. $this->extra = $extra;
  683. $this->paginator = $paginator;
  684. # number of pages
  685. $this->nbpages = ceil($this->itemcount / $this->max);
  686. # number of current page
  687. $this->curpage = floor(($this->curend + 1) / $this->max);
  688. }
  689. function display() {
  690. echo '<form method="post">';
  691. echo "<ul class=\"navList\">\n";
  692. if ($this->curstart == 0 || ($this->curstart - $this->max < 0))
  693. echo "<li class=\"previousListInactive\">"._("Previous")."</li>\n";
  694. else {
  695. $start = $this->curstart - $this->max;
  696. $end = $this->curstart - 1;
  697. echo "<li class=\"previousList\"><a href=\"".$_SERVER["SCRIPT_NAME"];
  698. /* FIXME: maybe we can get rid of $_GET["filter"] ? */
  699. printf("?module=%s&amp;submod=%s&amp;action=%s&amp;start=%d&amp;end=%d&amp;filter=%s%s", $_GET["module"],$_GET["submod"],$_GET["action"],$start, $end, $_GET["filter"], $this->extra);
  700. echo "\">"._("Previous")."</a></li>\n";
  701. }
  702. if($this->paginator) {
  703. // Display the maxperpage selector
  704. $this->displaySelectMax();
  705. }
  706. if (($this->curend + 1) >= $this->itemcount)
  707. echo "<li class=\"nextListInactive\">"._("Next")."</li>\n";
  708. else {
  709. $start = $this->curend + 1;
  710. $end = $this->curend + $this->max;
  711. echo "<li class=\"nextList\"><a href=\"".$_SERVER["SCRIPT_NAME"];
  712. printf("?module=%s&amp;submod=%s&amp;action=%s&amp;start=%d&amp;end=%d&amp;filter=%s%s", $_GET["module"],$_GET["submod"],$_GET["action"],$start, $end, $_GET["filter"], $this->extra);
  713. echo "\">"._("Next")."</a></li>\n";
  714. }
  715. if($this->paginator) {
  716. // Display a border at the left of the "Next" link
  717. $this->displayNextListBorder();
  718. }
  719. echo "</ul>\n";
  720. }
  721. /*
  722. * This function displays a selector to choose the maxperpage value
  723. * dynamically.
  724. * This is useful with AjaxNavBar
  725. * @param $jsfunc: optional javascript function which updates ListInfos
  726. */
  727. function displaySelectMax($jsfunc=null) {
  728. global $conf;
  729. echo '<span class="pagination">'._('Pagination').': ';
  730. if(isset($jsfunc)) {
  731. $start = $this->curstart;
  732. echo "<select id=\"maxperpage\" name=\"maxperpage\" onChange=\"updateMaxPerPage(this); return false;\" class=\"pagination\">";
  733. } else {
  734. echo "<select id=\"maxperpage\" name=\"maxperpage\" class=\"pagination\">";
  735. }
  736. /* Display the selector and each option of the array set in the config
  737. file */
  738. foreach($conf["global"]["pagination"] as $quantity) {
  739. $selected = '';
  740. if ($_REQUEST['maxperpage'] == $quantity)
  741. /* Set by default if already selected before */
  742. $selected = ' selected="selected"';
  743. echo "<option value=\"$quantity\"$selected>$quantity</option>";
  744. }
  745. echo "</select></span>";
  746. /*
  747. * Print the script which will launch an update of the ListInfos when
  748. * selectMax value changes.
  749. * It also synchronizes the value of the two selectors of the widget.
  750. * Then it calls the javascript function which do an AJAX update of
  751. * the ListInfos.
  752. */
  753. ?>
  754. <script type="javascript">
  755. updateMaxPerPage = function(elem) {
  756. // Get the selector element (the first of the page)
  757. var maxperpageElement = document.getElementById('maxperpage');
  758. if(maxperpageElement != undefined) {
  759. // Synchronize the value of the two selectors of the page :
  760. // the ListInfos widget print two Navbar, so the maxperpage value can be changed in both
  761. maxperpageElement.selectedIndex = elem.selectedIndex;
  762. var maxperpageValue = elem.value;
  763. // Evaluate the end depending on the maxperpage value selected
  764. var end = parseInt(maxperpageValue) + parseInt(<?php echo $start ?>) - 1;
  765. // Call the function to update the ListInfos
  766. <?php echo $jsfunc ?>('<?php echo $this->filter ?>', '<?php echo $start ?>', end);
  767. }
  768. return false;
  769. }
  770. </script>
  771. <?
  772. }
  773. /**
  774. * This function just print a script which add a border at the left of the "Next" link
  775. */
  776. function displayNextListBorder() {
  777. ?>
  778. <script type="javascript">
  779. var nextList = [];
  780. var nextListClass = "";
  781. if(document.getElementsByClassName("nextListInactive").length > 0) {
  782. nextListClass = "nextListInactive";
  783. }
  784. if(document.getElementsByClassName("nextList").length > 0) {
  785. nextListClass = "nextList";
  786. }
  787. if(nextListClass != "") {
  788. nextList = document.getElementsByClassName(nextListClass);
  789. nextList[0].style.borderLeft = "solid 1px #CCC";
  790. nextList[1].style.borderLeft = "solid 1px #CCC";
  791. }
  792. </script>
  793. <?
  794. }
  795. function displayGotoPageField() {
  796. echo '<script type="text/javascript">
  797. gotoPage = function(input) {
  798. page = input.value;
  799. if (page <= '.$this->nbpages.') {
  800. end = ('.$this->max.' * page);
  801. start = end - '.$this->max.';
  802. end -= 1;
  803. cur = ('.$this->curend.' + 1) / 10;
  804. '.$this->jsfunc.'("'.$this->filter.'", start, end, document.getElementById("maxperpage"));
  805. }
  806. }
  807. </script>';
  808. echo '<span class="pagination">'._("Go to page").': <input type="input" size="2" onchange="gotoPage(this)" /></span>';
  809. }
  810. function displayPagesNumbers() {
  811. # pages links
  812. # show all pages
  813. if ($this->nbpages <= 10) {
  814. if($this->nbpages > 1) {
  815. echo '<span class="pagination">';
  816. for($i=1; $i<=$this->nbpages; $i++) {
  817. echo $this->makePageLink($i);
  818. }
  819. echo '</span>';
  820. }
  821. }
  822. # show start/end pages and current page
  823. else {
  824. echo '<span class="pagination">';
  825. for($i=1; $i<=3; $i++) {
  826. echo $this->makePageLink($i);
  827. }
  828. if($this->curpage > 2 and $this->curpage < 5) {
  829. for($i=$this->curpage;$i<=$this->curpage+2;$i++) {
  830. if ($i > 3)
  831. echo $this->makePageLink($i);
  832. }
  833. }
  834. else if ($this->curpage > 4 and $this->curpage < $this->nbpages-3) {
  835. echo '.. ';
  836. for($i=$this->curpage-1;$i<=$this->curpage+1;$i++) {
  837. echo $this->makePageLink($i);
  838. }
  839. }
  840. echo '.. ';
  841. if ($this->curpage <= $this->nbpages-2 and $this->curpage >= $this->nbpages-3) {
  842. for($i=$this->nbpages-4; $i<=$this->nbpages-3; $i++) {
  843. echo $this->makePageLink($i);
  844. }
  845. }
  846. for($i=$this->nbpages-2; $i<=$this->nbpages; $i++) {
  847. echo $this->makePageLink($i);
  848. }
  849. echo '</span>';
  850. }
  851. }
  852. function makePageLink($page) {
  853. $end = ($this->max * $page);
  854. $start = $end - $this->max;
  855. $end -= 1;
  856. if ($page == $this->curpage) {
  857. return '<span>'.$page.'</span> ';
  858. }
  859. else {
  860. return '<a href="#" onclick="'.$this->jsfunc.'(\''.$this->filter.'\',\''.$start.'\',\''.$end.'\', document.getElementById(\'maxperpage\')); return false;">'.$page.'</a> ';
  861. }
  862. }
  863. }
  864. /**
  865. * Class which creates a SimpleNavBar with the paginator always enabled by
  866. * default
  867. */
  868. class SimplePaginator extends SimpleNavBar {
  869. /**
  870. * Just call the constructor of SimpleNavBar with "true" value for the
  871. * $paginator attribute
  872. *
  873. * @param $curstart: the first item index to display
  874. * @param $curent: the last item index
  875. * @param $itemcount: total number of item
  876. * @param $filter: the current list filter
  877. * @param $max: max quantity of elements in a page
  878. */
  879. function SimplePaginator($curstart, $curend, $itemcount, $extra = "", $max = "") {
  880. $this->SimpleNavBar($curstart, $curend, $itemcount, $extra, $max, true);
  881. }
  882. }
  883. /**
  884. * Display a previous/next navigation bar for ListInfos widget
  885. * The AjaxNavBar is useful when an Ajax Filter is set for a ListInfos widget
  886. */
  887. class AjaxNavBar extends SimpleNavBar {
  888. /**
  889. *
  890. * The AjaxNavBar start/end item are get from $_GET["start"] and
  891. * $_GET["end"]
  892. *
  893. * @param $itemcount: total number of item
  894. * @param $filter: the current list filter
  895. * @param $extra: extra URL parameter to pass the next/list button
  896. * @param $jsfunc: the name of the javascript function that applies the AJAX filter for the ListInfos widget
  897. * @param $max: the max number of elements to display in a page
  898. */
  899. function AjaxNavBar($itemcount, $filter, $jsfunc = "updateSearchParam", $max = "", $paginator = false) {
  900. global $conf;
  901. if (isset($_GET["start"])) {
  902. $curstart = $_GET["start"];
  903. $curend = $_GET["end"];
  904. } else {
  905. $curstart = 0;
  906. if ($itemcount > 0){
  907. if($max != "") {
  908. $curend = $max -1;
  909. } else {
  910. $curend = $conf["global"]["maxperpage"] - 1;
  911. }
  912. } else
  913. $curend = 0;
  914. }
  915. $this->SimpleNavBar($curstart, $curend, $itemcount, null, $max, $paginator);
  916. $this->filter = $filter;
  917. $this->jsfunc = $jsfunc;
  918. }
  919. function display() {
  920. echo '<form method="post">';
  921. echo "<ul class=\"navList\">\n";
  922. if($this->paginator) {
  923. // Display the maxperpage selector
  924. $this->displaySelectMax($this->jsfunc);
  925. }
  926. // show goto page field
  927. if ($this->nbpages > 20) {
  928. $this->displayGotoPageField();
  929. }
  930. # previous link
  931. if ($this->curstart == 0 || ($this->curstart - $this->max < 0))
  932. echo "<li class=\"previousListInactive\">" . _("Previous") . "</li>\n";
  933. else {
  934. $start = $this->curstart - $this->max;
  935. $end = $this->curstart - 1;
  936. echo "<li class=\"previousList\"><a href=\"#\" onClick=\"" . $this->jsfunc . "('" . $this->filter . "','$start','$end', document.getElementById('maxperpage')); return false;\">" . _("Previous") . "</a></li>\n";
  937. }
  938. // display pages numbers
  939. $this->displayPagesNumbers();
  940. # next link
  941. if (($this->curend + 1) >= $this->itemcount)
  942. echo "<li class=\"nextListInactive\">"._("Next")."</li>\n";
  943. else {
  944. $start = $this->curend + 1;
  945. $end = $this->curend + $this->max;
  946. echo "<li class=\"nextList\"><a href=\"#\" onClick=\"" . $this->jsfunc . "('" . $this->filter . "','$start','$end', document.getElementById('maxperpage')); return false;\">" . _("Next") . "</a></li>\n";
  947. }
  948. // Display a border at the left of the "Next" link
  949. if ($this->nbpages > 1) {
  950. $this->displayNextListBorder();
  951. }
  952. echo "</ul>\n";
  953. }
  954. }
  955. /**
  956. * Class which creates an AjaxNavBar with the paginator always enabled by
  957. * default
  958. */
  959. class AjaxPaginator extends AjaxNavBar {
  960. /**
  961. * Just call the constructor of AjaxNavBar with "true" value for the $paginator attribute
  962. *
  963. * @param $itemcount: total number of item
  964. * @param $filter: the current list filter
  965. * @param $jsfunc: the name of the javascript function that applies the AJAX filter for the ListInfos widget
  966. * @param $max: the max number of elements to display in a page
  967. */
  968. function AjaxPaginator($itemcount, $filter, $jsfunc = "updateSearchParam", $max = "") {
  969. $this->AjaxNavBar($itemcount, $filter, $jsfunc, $max, true);
  970. }
  971. }
  972. /**
  973. *
  974. * Create an AjaxFilter Form that updates a div according to an url output
  975. *
  976. */
  977. class AjaxFilter extends HtmlElement {
  978. /**
  979. * @param $url: URL called by the javascript updated. The URL gets the filter in $_GET["filter"]
  980. * @param $divid: div ID which is updated by the URL output
  981. * @param $formid: change the form id (usefull for multiple Ajaxfilter in one page)
  982. */
  983. function AjaxFilter($url, $divid = "container", $params = array(), $formid = "") {
  984. if (strpos($url, "?") === False)
  985. /* Add extra ? needed to build the URL */
  986. $this->url = $url . "?";
  987. else
  988. /* Add extra & needed to build the URL */
  989. $this->url = $url . "&";
  990. $this->divid = $divid;
  991. $this->formid = $formid;
  992. $this->refresh= 0;
  993. $this->params = '';
  994. foreach ($params as $k => $v) {
  995. $this->params .= "&".$k."=".$v;
  996. }
  997. // get the current module pages
  998. if (isset($_GET["module"]))
  999. $__module = $_GET["module"];
  1000. else
  1001. $__module = "default";
  1002. if (isset($_GET["submod"]))
  1003. $__submod = $_GET["submod"];
  1004. else
  1005. $__submod = "default";
  1006. if (isset($_GET["action"]))
  1007. $__action = $_GET["action"];
  1008. else
  1009. $__action = "default";
  1010. if (isset($_GET['tab']))
  1011. $__tab = $_GET['tab'];
  1012. else
  1013. $__tab = "default";
  1014. $extra = "";
  1015. foreach($_GET as $key => $value) {
  1016. if (!in_array($key, array('module', 'submod', 'tab', 'action', 'filter', 'start', 'end', 'maxperpage')))
  1017. $extra += $key + "_" + $value;
  1018. }
  1019. // then get our filter info
  1020. if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_filter_".$extra])) {
  1021. $this->storedfilter = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_filter_".$extra];
  1022. }
  1023. if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_maxperpage_".$extra])) {
  1024. $this->storedmax = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_maxperpage_".$extra];
  1025. }
  1026. if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_start_".$extra])) {
  1027. $this->storedstart = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_start_".$extra];
  1028. }
  1029. if(isset($_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_end_".$extra])) {
  1030. $this->storedend = $_SESSION[$__module."_".$__submod."_".$__action."_".$__tab."_end_".$extra];
  1031. }
  1032. }
  1033. /**
  1034. * Allow the list to refresh
  1035. * @param $refresh: time in ms
  1036. */
  1037. function setRefresh($refresh) {
  1038. $this->refresh = $refresh;
  1039. }
  1040. function display() {
  1041. global $conf;
  1042. $root = $conf["global"]["root"];
  1043. $maxperpage = $conf["global"]["maxperpage"];
  1044. ?>
  1045. <form name="Form<?php echo $this->formid ?>" id="Form<?php echo $this->formid ?>" action="#" onsubmit="return false;">
  1046. <div id="loader<?php echo $this->formid ?>">
  1047. <img id="loadimg" src="<?php echo $root; ?>img/common/loader.gif" alt="loader" class="loader"/>
  1048. </div>
  1049. <div id="searchSpan<?php echo $this->formid ?>" class="searchbox" style="float: right;">
  1050. <img src="graph/search.gif" style="position:relative; top: 2px; float: left;" alt="search" /> <span class="searchfield"><input type="text" class="searchfieldreal" name="param" id="param<?php echo $this->formid ?>" onkeyup="pushSearch<?php echo $this->formid ?>(); return false;" />
  1051. <img src="graph/croix.gif" alt="suppression" style="position:relative; top : 3px;"
  1052. onclick="document.getElementById('param<?php echo $this->formid ?>').value =''; pushSearch<?php echo $this->formid ?>(); return false;" />
  1053. </span>
  1054. </div>
  1055. <script type="text/javascript">
  1056. <?
  1057. if(!$this->formid) {
  1058. ?>
  1059. document.getElementById('param<?php echo $this->formid ?>').focus();
  1060. <?
  1061. }
  1062. if(isset($this->storedfilter)) {
  1063. ?>
  1064. document.Form<?php echo $this->formid ?>.param.value = "<?php echo $this->storedfilter ?>";
  1065. <?
  1066. }
  1067. ?>
  1068. var refreshtimer<?php echo $this->formid ?> = null;
  1069. var refreshparamtimer<?php echo $this->formid ?> = null;
  1070. var refreshdelay<?php echo $this->formid ?> = <?php echo $this->refresh ?>;
  1071. var maxperpage = <?php echo $maxperpage ?>;
  1072. <?
  1073. if (isset($this->storedmax)) {
  1074. ?>
  1075. maxperpage = <?php echo $this->storedmax ?>;
  1076. <?
  1077. }
  1078. ?>
  1079. if(document.getElementById('maxperpage') != undefined)
  1080. maxperpage = document.getElementById('maxperpage').value;
  1081. /**
  1082. * Clear the timers set vith setTimeout
  1083. */
  1084. clearTimers<?php echo $this->formid ?> = function() {
  1085. if (refreshtimer<?php echo $this->formid ?> != null) {
  1086. clearTimeout(refreshtimer<?php echo $this->formid ?>);
  1087. }
  1088. if (refreshparamtimer<?php echo $this->formid ?> != null) {
  1089. clearTimeout(refreshparamtimer<?php echo $this->formid ?>);
  1090. }
  1091. }
  1092. /**
  1093. * Update div
  1094. */
  1095. <?php
  1096. $url = $this->url."filter='+document.Form".$this->formid.".param.value+'&maxperpage='+maxperpage+'".$this->params;
  1097. if (isset($this->storedstart) && isset($this->storedend)) {
  1098. $url .= "&start=".$this->storedstart."&end=".$this->storedend;
  1099. }
  1100. ?>
  1101. updateSearch<?php echo $this->formid ?> = function() {
  1102. new Ajax.Updater('<?php echo $this->divid; ?>',
  1103. '<?php echo $url ?>',
  1104. { asynchronous:true, evalScripts: true}
  1105. );
  1106. <?
  1107. if ($this->refresh) {
  1108. ?>
  1109. refreshtimer<?php echo $this->formid ?> = setTimeout("updateSearch<?php echo $this->formid ?>()", refreshdelay<?php echo $this->formid ?>)
  1110. <?
  1111. }
  1112. ?>
  1113. }
  1114. /**
  1115. * Update div when clicking previous / next
  1116. */
  1117. updateSearchParam<?php echo $this->formid ?> = function(filter, start, end, max) {
  1118. clearTimers<?php echo $this->formid ?>();
  1119. if(document.getElementById('maxperpage') != undefined)
  1120. maxperpage = document.getElementById('maxperpage').value;
  1121. new Ajax.Updater('<?php echo $this->divid; ?>','<?php echo $this->url; ?>filter='+filter+'&start='+start+'&end='+end+'&maxperpage='+maxperpage+'<?php echo $this->params ?>', { asynchronous:true, evalScripts: true});
  1122. <?
  1123. if ($this->refresh) {
  1124. ?>
  1125. refreshparamtimer<?php echo $this->formid ?> = setTimeout("updateSearchParam<?php echo $this->formid ?>('"+filter+"',"+start+","+end+","+maxperpage+")", refreshdelay<?php echo $this->formid ?>);
  1126. <?
  1127. }
  1128. ?>
  1129. }
  1130. /**
  1131. * wait 500ms and update search
  1132. */
  1133. pushSearch<?php echo $this->formid ?> = function() {
  1134. clearTimers<?php echo $this->formid ?>();
  1135. refreshtimer<?php echo $this->formid ?> = setTimeout("updateSearch<?php echo $this->formid ?>()", 500);
  1136. }
  1137. pushSearch<?php echo $this->formid ?>();
  1138. </script>
  1139. </form>
  1140. <?
  1141. }
  1142. function displayDivToUpdate() {
  1143. print '<div id="' . $this->divid . '"></div>' . "\n";
  1144. }
  1145. }
  1146. class NoLocationTpl extends AbstractTpl {
  1147. function NoLocationTpl($name) {
  1148. $this->name = $name;
  1149. $this->size = '13';
  1150. }
  1151. function display() {
  1152. print '<span class="error">' . _("No item available") . '</span>';
  1153. print '<input name="'.$this->name.'" id="'.$this->name.'" type="HIDDEN" size="'.$this->size.'" value="" class="searchfieldreal" />';
  1154. }
  1155. function setSelected($elemnt) {
  1156. }
  1157. }
  1158. class SingleLocationTpl extends AbstractTpl {
  1159. function SingleLocationTpl($name, $label) {
  1160. $this->name = $name;
  1161. $this->label = $label;
  1162. $this->value = null;
  1163. }
  1164. function setElementsVal($value) {
  1165. $this->value = array_values($value);
  1166. $this->value = $this->value[0];
  1167. }
  1168. function setSelected($elemnt) {
  1169. }
  1170. function display() {
  1171. print $this->label;
  1172. print '<input name="'.$this->name.'" id="'.$this->name.'" type="HIDDEN" value="'. $this->value .'" class="searchfieldreal" />';
  1173. }
  1174. }
  1175. class AjaxFilterLocation extends AjaxFilter {
  1176. function AjaxFilterLocation($url, $divid = "container", $paramname = 'location', $params = array()) {
  1177. $this->AjaxFilter($url, $divid, $params);
  1178. $this->location = new SelectItem($paramname, 'pushSearch', 'searchfieldreal noborder');
  1179. $this->paramname = $paramname;
  1180. }
  1181. function setElements($elt) {
  1182. if (count($elt) == 0) {
  1183. $this->location = new NoLocationTpl($this->paramname);
  1184. } else if (count($elt) == 1) {
  1185. $loc = array_values($elt);
  1186. $this->location = new SingleLocationTpl($this->paramname, $loc[0]);
  1187. } else {
  1188. $this->location->setElements($elt);
  1189. }
  1190. }
  1191. function setElementsVal($elt) {
  1192. if (count($elt) >= 1) {
  1193. $this->location->setElementsVal($elt);
  1194. }
  1195. }
  1196. function setSelected($elemnt) {
  1197. $this->location->setSelected($elemnt);
  1198. }
  1199. function display() {
  1200. global $conf;
  1201. $root = $conf["global"]["root"];
  1202. ?>
  1203. <form name="Form" id="Form" action="#" onsubmit="return false;">
  1204. <div id="loader"><img id="loadimg" src="<?php echo $root; ?>img/common/loader.gif" alt="loader" class="loader"/></div>
  1205. <div id="searchSpan" class="searchbox" style="float: right;">
  1206. <img src="graph/search.gif" style="position:relative; top: 2px; float: left;" alt="search" />
  1207. <span class="searchfield">
  1208. <?php
  1209. $this->location->display();
  1210. ?>
  1211. </span>&nbsp;
  1212. <span class="searchfield"><input type="text" class="searchfieldreal" name="param" id="param" onkeyup="pushSearch(); return false;" />
  1213. <img src="graph/croix.gif" alt="suppression" style="position:relative; top : 3px;"
  1214. onclick="document.getElementById('param').value =''; pushSearch(); return false;" />
  1215. </span>
  1216. </div>
  1217. <script type="text/javascript">
  1218. document.getElementById('param').focus();
  1219. <?
  1220. if(isset($this->storedfilter)) {
  1221. ?>
  1222. document.Form.param.value = "<?php echo $this->storedfilter ?>";
  1223. <?
  1224. }
  1225. ?>
  1226. var maxperpage = 10;
  1227. if(document.getElementById('maxperpage') != undefined)
  1228. maxperpage = document.getElementById('maxperpage').value;
  1229. /**
  1230. * update div with user
  1231. */
  1232. function updateSearch() {
  1233. launch--;
  1234. if (launch==0) {
  1235. new Ajax.Updater('<?php echo $this->divid; ?>','<?php echo $this->url; ?>filter='+document.Form.param.value+'<?php echo $this->params ?>&<?php echo $this->paramname ?>='+document.Form.<?php echo $this->paramname ?>.value+'&maxperpage='+maxperpage, { asynchronous:true, evalScripts: true});
  1236. }
  1237. }
  1238. /**
  1239. * provide navigation in ajax for user
  1240. */
  1241. function updateSearchParam(filt, start, end) {
  1242. var reg = new RegExp("##", "g");
  1243. var tableau = filt.split(reg);
  1244. var location = "";
  1245. var filter = "";
  1246. var reg1 = new RegExp(tableau[0]+"##", "g");
  1247. if (filt.match(reg1)) {
  1248. if (tableau[0] != undefined) {
  1249. filter = tableau[0];
  1250. }
  1251. if (tableau[1] != undefined) {
  1252. location = tableau[1];
  1253. }
  1254. } else if (tableau.length == 1) {
  1255. if (tableau[0] != undefined) {
  1256. location = tableau[0];
  1257. }
  1258. }
  1259. if(document.getElementById('maxperpage') != undefined)
  1260. {
  1261. maxperpage = document.getElementById('maxperpage').value;
  1262. }
  1263. new Ajax.Updater('<?php echo $this->divid; ?>','<?php echo $this->url; ?>filter='+filter+'<?php echo $this->params ?>&<?php echo $this->paramname ?>='+location+'&start='+start+'&end='+end+'&maxperpage='+maxperpage, { asynchronous:true, evalScripts: true});
  1264. }
  1265. /**
  1266. * wait 500ms and update search
  1267. */
  1268. function pushSearch() {
  1269. launch++;
  1270. setTimeout("updateSearch()",500);
  1271. }
  1272. pushSearch();
  1273. </script>
  1274. </form>
  1275. <?
  1276. }
  1277. }
  1278. class AjaxLocation extends AjaxFilterLocation {
  1279. function AjaxLocation($url, $divid = "container", $paramname = 'location', $params = array()) {
  1280. $this->AjaxFilterLocation($url, $divid, $paramname, $params);
  1281. $this->location = new SelectItem($paramname, 'pushSearchLocation', 'searchfieldreal noborder');
  1282. }
  1283. function display() {
  1284. global $conf;
  1285. $root = $conf["global"]["root"];
  1286. ?>
  1287. <form name="FormLocation" id="FormLocation" action="#">
  1288. <div id="Location">
  1289. <span id="searchSpan" class="searchbox">
  1290. <img src="graph/search.gif"/>
  1291. <span class="locationtext">&nbsp;<?php echo _("Select entity") ?>:&nbsp;</span>
  1292. <span class="locationfield">
  1293. <?php
  1294. $t

Large files files are truncated, but you can click here to view the full file