Exemplo n.º 1
0
 /**
  * Wraps the content with the layout header
  */
 public static function wrap($content, $title = NULL, $use_blank = false)
 {
     $theme = self::getCurrentTheme();
     $template['THEME_HTTP'] = Layout::getThemeHttpRoot() . $theme . '/';
     $template['CONTENT'] = $content;
     Layout::loadHeaderTags($template);
     if (isset($title)) {
         $template['PAGE_TITLE'] = strip_tags($title);
     }
     if ($use_blank) {
         $empty_tpl = sprintf('%sthemes/%s/blank.tpl', PHPWS_SOURCE_DIR, Layout::getCurrentTheme());
         if (is_file($empty_tpl)) {
             $result = PHPWS_Template::process($template, 'layout', $empty_tpl, TRUE);
             return $result;
         }
     }
     $result = PHPWS_Template::process($template, 'layout', 'header.tpl');
     return $result;
 }
Exemplo n.º 2
0
 public function setThemeFile($module, $file)
 {
     $current_theme = \Layout::getCurrentTheme();
     $this->theme_file = implode('', array(PHPWS_SOURCE_DIR, 'themes/', $current_theme, '/', 'templates/', $module, '/', $file));
 }
Exemplo n.º 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;
 }
Exemplo n.º 4
0
 private static function boxMoveForm()
 {
     $current_theme = \Layout::getCurrentTheme();
     $db = \Database::getDB();
     $tbl = $db->addTable('layout_box');
     $tbl->addFieldConditional('theme', $current_theme);
     $tbl->addFieldConditional('active', 1);
     $tbl->addOrderBy('theme_var');
     $tbl->addOrderBy('box_order');
     $boxes = $db->select();
     $theme_vars = $_SESSION['Layout_Settings']->_allowed_move;
     $move_select = '<optgroup label="Shift within current variable">' . '<option>Click below to move this block</option>' . '<option value="move_box_top">Top</option>' . '<option value="move_box_up">Up</option>' . '<option value="move_box_down">Down</option>' . '<option value="move_box_bottom">Bottom</option>' . '</optgroup>' . '<optgroup label="Move to theme variable">';
     foreach ($theme_vars as $tv) {
         $listing[$tv] = null;
         $move_select .= "<option>{$tv}</option>";
     }
     $move_select .= '</optgroup></select>';
     foreach ($boxes as $box) {
         $box_name = $box['module'] . ':' . $box['content_var'];
         $listing[$box['theme_var']][$box['box_order']] = array('id' => $box['id'], 'name' => $box_name);
     }
     //var_dump($listing);exit;
     $template = new \Template(array('rows' => $listing, 'move_select' => $move_select));
     $template->setModuleTemplate('layout', 'box_move.html');
     echo $template->get();
     exit;
 }
Exemplo n.º 5
0
 public function setThemeFile($module, $file)
 {
     if (!class_exists('Layout')) {
         $db = \Database::getDB();
         $lc = $db->addTable('layout_config');
         $row = $db->selectOneRow();
         $current_theme = $row['default_theme'];
     } else {
         $current_theme = \Layout::getCurrentTheme();
     }
     $this->theme_file = implode('', array(PHPWS_SOURCE_DIR, 'themes/', $current_theme, '/', 'templates/', $module, '/', $file));
 }