Example #1
0
 /**
  * serialise the token
  * @access public
  * @return string
  */
 public function __toString()
 {
     $formHidden = new Form_Hidden('token');
     $formHidden->setValue($this->_token);
     return $formHidden->__toString();
 }
Example #2
0
 public static function formHidden($name, $value = null)
 {
     $element = new Form_Hidden($name, $value);
     return $element->get();
 }
Example #3
0
 /**
  * Returns a list of items based on the table currently set in this manager
  *
  * @param  string  $listName The name of the list wanting to be returned
  * @param  string  $title    The title of the list
  * @param  boolean $makeForm Flag whether or not to make a form out of the list
  * @access public
  */
 function getList($listName, $title = NULL, $makeForm = TRUE, $overRideOp = NULL)
 {
     $this->listName = $listName;
     if (!isset($this->_table) && !isset($this->_request)) {
         $message = _('Manager was not fully initialized to get a list.');
         $error = new PHPWS_Error('core', 'PHPWS_Manager::getList()', $message, 'exit', 1);
         $error->message(NULL);
     }
     $theme = Layout::getCurrentTheme();
     $themeModuleRowTpl = "themes/{$theme}/templates/" . $this->_module . '/' . $this->_templates[$this->listName] . '/row.tpl';
     $moduleRowTpl = PHPWS_SOURCE_DIR . 'mod/' . $this->_module . '/templates/' . $this->_templates[$this->listName] . '/row.tpl';
     $themeCoreRowTpl = 'themes/' . $theme . '/templates/core/defaultRow.tpl';
     $coreRowTpl = PHPWS_SOURCE_DIR . 'templates/defaultRow.tpl';
     $themeModuleListTpl = "themes/{$theme}/templates/" . $this->_module . '/' . $this->_templates[$this->listName] . '/list.tpl';
     $moduleListTpl = PHPWS_SOURCE_DIR . 'mod/' . $this->_module . '/templates/' . $this->_templates[$this->listName] . '/list.tpl';
     $themeCoreListTpl = "themes/{$theme}/templates/core/defaultList.tpl";
     $coreListTpl = PHPWS_SOURCE_DIR . 'templates/defaultList.tpl';
     if (file_exists($themeModuleRowTpl)) {
         $rowTpl = $themeModuleRowTpl;
     } else {
         if (file_exists($moduleRowTpl)) {
             $rowTpl = $moduleRowTpl;
         } else {
             if (file_exists($themeCoreRowTpl)) {
                 $rowTpl = $themeCoreRowTpl;
             } else {
                 $rowTpl = $coreRowTpl;
             }
         }
     }
     if (file_exists($themeModuleListTpl)) {
         $listTpl = $themeModuleListTpl;
     } else {
         if (file_exists($moduleListTpl)) {
             $listTpl = $moduleListTpl;
         } else {
             if (file_exists($themeCoreListTpl)) {
                 $listTpl = $themeCoreListTpl;
             } else {
                 $listTpl = $coreListTpl;
             }
         }
     }
     if (isset($_REQUEST['PHPWS_MAN_LIST']) && $this->listName == $_REQUEST['PHPWS_MAN_LIST']) {
         $this->catchOrder();
     }
     if (isset($overRideOp)) {
         $op = $overRideOp;
     } else {
         if (isset($this->_listPaging[$this->listName]['op'])) {
             $op = $this->_listPaging[$this->listName]['op'];
         }
     }
     if (isset($this->_listPaging[$this->listName]) && is_array($this->_listPaging[$this->listName])) {
         if (!isset($this->_pagers[$this->listName])) {
             $this->_pagers[$this->listName] = new PHPWS_Pager();
             $this->_pagers[$this->listName]->setLinkBack('./index.php?module=' . $this->_module . '&' . $op . '&PHPWS_MAN_PAGE=' . $this->listName);
             $this->_pagers[$this->listName]->setLimits($this->_listPaging[$this->listName]['limits']);
             $this->_pagers[$this->listName]->makeArray(TRUE);
             if ($this->_anchor) {
                 $this->_pagers[$this->listName]->setAnchor('#' . $this->listName);
             }
             $this->_pagers[$this->listName]->limit = $this->_listPaging[$this->listName]['limit'];
         }
         $this->_pagers[$this->listName]->setData($this->_getIds());
         if (isset($_REQUEST['PHPWS_MAN_PAGE']) && $this->listName == $_REQUEST['PHPWS_MAN_PAGE']) {
             $this->_pagers[$this->listName]->pageData();
         } else {
             $this->_pagers[$this->listName]->pageData(FALSE);
         }
         if (isset($this->_class)) {
             $items = $this->getItems($this->_pagers[$this->listName]->getData(), FALSE, TRUE);
         } else {
             $items = $this->getItems($this->_pagers[$this->listName]->getData());
         }
         $totalItems = count($items);
         //            $totalItems = $this->_pagers[$this->listName]->getNumRows();
     } else {
         if (isset($this->_class)) {
             $items = $this->getItems(NULL, FALSE, TRUE);
         } else {
             $items = $this->getItems();
         }
         $totalItems = sizeof($items);
     }
     /* Begin building main list tags array for processTemplate() */
     $listTags = array();
     if (isset($this->_listExtraLabels) && is_array($this->_listExtraLabels)) {
         $listTags = $this->_listExtraLabels;
     }
     $listTags['TITLE'] = $title;
     $listTags['ANCHOR'] = '<a id="' . $this->listName . '" name="' . $this->listName . '"></a>';
     if ($makeForm) {
         $listTags['SELECT_LABEL'] = '&#160;';
     }
     $columns = 0;
     foreach ($this->_listColumns[$this->listName] as $listColumn => $listLabel) {
         $column = strtoupper($listColumn);
         $key0 = $column . '_LABEL';
         $key1 = $column . '_ORDER_LINK';
         $listTags[$key0] = NULL;
         $listTags[$key1] = NULL;
         $listTags[$key0] = $listLabel;
         if (isset($overRideOp)) {
             $request = $overRideOp;
         } else {
             if (isset($this->_listPaging[$this->listName]['op'])) {
                 $request = $this->_listPaging[$this->listName]['op'];
             } else {
                 $request = $this->_request . '=list';
             }
         }
         if ($totalItems > 0) {
             $anchor = '';
             if ($this->_anchor) {
                 $anchor = '#' . $this->listName;
             }
             if (isset($this->_overrideOrder[$this->listName][$listColumn][0])) {
                 $overRide = $this->_overrideOrder[$this->listName][$listColumn][0];
             } else {
                 $overRide = 'default';
             }
             if (isset($this->_listPaging[$this->listName])) {
                 switch ($overRide) {
                     case 0:
                         $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&amp;' . $request . '&amp;PHPWS_MAN_LIST=' . $this->listName . '&amp;PHPWS_MAN_COLUMN=' . $listColumn . '&amp;PHPWS_MAN_ORDER=1&amp;' . 'PHPWS_MAN_PAGE=' . $this->listName . '&amp;' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&amp;' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&amp;' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">';
                         $listTags[$key1] .= Icon::show('sort') . '</a>';
                         break;
                     case 1:
                         $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&amp;' . $request . '&amp;PHPWS_MAN_LIST=' . $this->listName . '&amp;PHPWS_MAN_COLUMN=' . $listColumn . '&amp;PHPWS_MAN_ORDER=2&amp;' . 'PHPWS_MAN_PAGE=' . $this->listName . '&amp;' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&amp;' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&amp;' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">';
                         $listTags[$key1] .= Icon::show('sort-up') . '</a>';
                         break;
                     case 2:
                         $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&amp;' . $request . '&amp;PHPWS_MAN_LIST=' . $this->listName . '&amp;PHPWS_MAN_COLUMN=' . $listColumn . '&amp;PHPWS_MAN_ORDER=0&amp;' . 'PHPWS_MAN_PAGE=' . $this->listName . '&amp;' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&amp;' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&amp;' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">';
                         $listTags[$key1] .= Icon::show('sort-down') . '</a>';
                         break;
                     default:
                         $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&amp;' . $request . '&amp;PHPWS_MAN_LIST=' . $this->listName . '&amp;PHPWS_MAN_COLUMN=' . $listColumn . '&amp;PHPWS_MAN_ORDER=1&amp;' . 'PHPWS_MAN_PAGE=' . $this->listName . '&amp;' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&amp;' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&amp;' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">';
                         $listTags[$key1] .= Icon::show('sort') . '</a>';
                 }
             }
         }
         $columns++;
     }
     /* Build each item's row */
     $listTags['LIST_ITEMS'] = NULL;
     if ($totalItems > 0) {
         $tog = 1;
         foreach ($items as $item) {
             $object = NULL;
             if (isset($this->_class)) {
                 $object = new $this->_class($item);
                 $className = get_class($object);
                 $classMethods = get_class_methods($className);
                 @array_walk($classMethods, 'manager_lower_methods');
                 $objectVars = get_object_vars($object);
                 if (is_array($objectVars)) {
                     $item = $objectVars;
                     foreach ($item as $key => $value) {
                         if ($key[0] == '_') {
                             $key = substr($key, 1, strlen($key));
                             $item[$key] = $value;
                         }
                     }
                 }
             }
             if ($tog % 2) {
                 $row_class = ' class="bgcolor1"';
             } else {
                 $row_class = null;
             }
             $tog++;
             /* Build row tags array for processTemplate() */
             $rowTags = array();
             if (isset($this->_listExtraLabels) && is_array($this->_listExtraLabels)) {
                 $rowTags = $this->_listExtraLabels;
             }
             $rowTags['ROW_CLASS'] = $row_class;
             if ($makeForm) {
                 $ele = new Form_CheckBox('PHPWS_MAN_ITEMS[]', $item['id']);
                 $rowTags['SELECT'] = $ele->get();
             }
             foreach ($this->_listColumns[$this->listName] as $listColumn => $listLabel) {
                 $column = strtoupper($listColumn);
                 if ($listColumn == 'created') {
                     /* Set created date using phpwebsite's default date and time formats */
                     $rowTags['CREATED'] = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $item['created']);
                 } else {
                     if ($listColumn == 'updated') {
                         /* Set updated date using phpwebsite's default date and time formats */
                         $rowTags['UPDATED'] = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $item['updated']);
                     } else {
                         if ($listColumn == 'hidden') {
                             /* Setting message depending if this item is hidden or not */
                             if (isset($this->_listValues['hidden'])) {
                                 $rowTags['HIDDEN'] = $this->_listValues['hidden'][$item['hidden']];
                             } else {
                                 if ($item['hidden'] == 1) {
                                     $rowTags['HIDDEN'] = _('Hidden');
                                 } else {
                                     $rowTags['HIDDEN'] = _('Visible');
                                 }
                             }
                         } else {
                             if ($listColumn == 'approved') {
                                 /* Setting message depending if this item is approved or not */
                                 if (isset($this->_listValues['hidden'])) {
                                     $rowTags['APPROVED'] = $this->_listValues['approved'][$item['approved']];
                                 } else {
                                     if ($item['approved'] == 1) {
                                         $rowTags['APPROVED'] = _('Approved');
                                     } else {
                                         $rowTags['APPROVED'] = _('Unapproved');
                                     }
                                 }
                             } else {
                                 if ($listColumn == 'groups') {
                                     $groups = unserialize($item['groups']);
                                     if (is_array($groups) && sizeof($groups) > 0) {
                                         /* Set flag to check whether to add a comma or not */
                                         $flag = FALSE;
                                         /* Create a string of group names the current item belongs to */
                                         foreach ($groups as $group) {
                                             if ($flag) {
                                                 $rowTags['GROUPS'] .= ', ';
                                             }
                                             $rowTags['GROUPS'] .= $group;
                                             $flag = TRUE;
                                         }
                                     } else {
                                         $rowTags['GROUPS'] = _('All');
                                     }
                                 } else {
                                     $method = 'get' . $listColumn;
                                     if (is_object($object) && in_array($method, $classMethods)) {
                                         $rowTags[$column] = $object->{$method}();
                                     } else {
                                         $rowTags[$column] = $item[$listColumn];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             /* Process this item and concatenate onto the current list of items */
             $listTags['LIST_ITEMS'] .= PHPWS_Template::processTemplate($rowTags, 'core', $rowTpl, FALSE);
         }
         if (isset($this->_listPaging[$this->listName]) && is_array($this->_listPaging[$this->listName]) && sizeof($this->_listPaging[$this->listName]) > 0) {
             $listTags['NAV_BACKWARD'] = $this->_pagers[$this->listName]->getBackLink($this->_listPaging[$this->listName]['back']);
             $listTags['NAV_FORWARD'] = $this->_pagers[$this->listName]->getForwardLink($this->_listPaging[$this->listName]['forward']);
             if (isset($this->_listPaging[$this->listName]['section'])) {
                 $listTags['NAV_SECTIONS'] = $this->_pagers[$this->listName]->getSectionLinks();
             }
             $listTags['NAV_LIMITS'] = $this->_pagers[$this->listName]->getLimitLinks();
             $listTags['NAV_INFO'] = $this->_pagers[$this->listName]->getSectionInfo();
         }
         $actions = array();
         if (isset($this->_listActions[$this->listName]) && is_array($this->_listActions[$this->listName])) {
             foreach ($this->_listActions[$this->listName] as $actionString => $actionLabel) {
                 if (isset($this->_listPermissions[$this->listName][$actionString])) {
                     $permission = $this->_listPermissions[$this->listName][$actionString];
                 }
                 if (isset($permission)) {
                     if (Current_User::allow($this->_module, $permission)) {
                         $actions[$actionString] = $actionLabel;
                     }
                 } else {
                     $actions[$actionString] = $actionLabel;
                 }
             }
         }
         if ($makeForm) {
             /* Create action select and Go button */
             $ele = new Form_Select($this->_request, $actions);
             $listTags['ACTION_SELECT'] = $ele->get();
             $listTags['ACTION_BUTTON'] = sprintf('<input type="submit" value="%s" />', _('Go'));
             $listTags['TOGGLE_ALL'] = javascript('check_all', array('FORM_NAME' => 'PHPWS_MAN_LIST_' . $this->listName));
             /* Add hidden variable to designate the current module */
             $ele = new Form_Hidden('module', $this->_module);
             $elements[0] = $ele->get();
             $elements[0] .= PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE);
             /* Create final form and dump it into a content variable to be returned */
             $content = sprintf('<form name="%s" action="index.php" method="post">%s</form>', 'PHPWS_MAN_LIST_' . $this->listName, implode("\n", $elements));
         } else {
             $content = PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE);
         }
     } else {
         $listTags['LIST_ITEMS'] = '<tr><td colspan="' . $columns . '">' . _('No items for the current list.') . '</td></tr>';
         $content = PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE);
     }
     /* reinitialize sort and order before next list */
     $this->setSort(NULL);
     $this->setOrder(NULL);
     $this->_class = NULL;
     return $content;
 }