コード例 #1
0
ファイル: Checkbox.php プロジェクト: HaldunA/phpwebsite
 /**
  * View this PHAT_Checkbox
  *
  * @return string The HTML content to view the PHAT_Checkbox
  * @access public
  */
 function view()
 {
     $label = $this->getLabel();
     if (isset($_REQUEST['PHAT_' . $label]) && is_array($_REQUEST['PHAT_' . $label])) {
         $this->setValue($_REQUEST['PHAT_' . $label]);
     }
     if ($this->isRequired()) {
         $viewTags['REQUIRED_FLAG'] = '*';
     }
     $viewTags['BLURB'] = PHPWS_Text::parseOutput($this->getBlurb(), ENCODE_PARSED_TEXT, false, true);
     $viewTags['CHECK_BOXES'] = '';
     $optionText = $this->getOptionText();
     $optionValues = $this->getOptionValues();
     $value = $this->getValue();
     $viewTags['CHECK_BOXES'] = null;
     for ($i = 0; $i < sizeof($optionText); $i++) {
         if (isset($value[$i])) {
             $match = $value[$i];
         } else {
             $match = null;
         }
         $option_value = $optionValues[$i];
         $element = new Form_CheckBox('PHAT_' . $label . '[' . $i . ']', $option_value);
         $element->setMatch($match);
         $id = preg_replace('/\\W/', '', $option_value) . $i;
         $element->setId($id);
         $label_text = "<label for='{$id}'>" . $optionText[$i] . "</label>";
         $viewTags['CHECK_BOXES'] .= $element->get() . " {$label_text}<br />\n";
     }
     return PHPWS_Template::processTemplate($viewTags, 'phatform', 'checkbox/view.tpl');
 }
コード例 #2
0
ファイル: Element.php プロジェクト: HaldunA/phpwebsite
 /**
  * Get the options for this PHAT_Element
  *
  * @return string The HTML form for retrieving the options
  * @access public
  */
 function getOptions()
 {
     $className = get_class($this);
     $properName = ucfirst(str_ireplace('phat_', '', $className));
     if (isset($_REQUEST['PHAT_OptionSet']) && $_REQUEST['PHAT_OptionSet'] != 0 && $_REQUEST['PHAT_OptionSet'] != $this->getOptionSet()) {
         $this->setOptionSet($_REQUEST['PHAT_OptionSet']);
         $db = new PHPWS_DB('mod_phatform_options');
         $db->addWhere('id', $this->getOptionSet());
         $optionResult = $db->select();
         $this->_optionText = array();
         $this->_optionValues = array();
         $this->_optionText = unserialize(stripslashes($optionResult[0]['optionSet']));
         $this->_optionValues = unserialize(stripslashes($optionResult[0]['valueSet']));
     }
     if (!empty($_REQUEST['PHAT_ElementNumOptions']) && is_numeric($_REQUEST['PHAT_ElementNumOptions'])) {
         $loops = $_REQUEST['PHAT_ElementNumOptions'];
         /* must reset these arrays for when a new number of options is entered */
         $oldText = $this->_optionText;
         $oldValues = $this->_optionValues;
         $this->_optionText = array();
         $this->_optionValues = array();
         for ($i = 0; $i < $loops; $i++) {
             if (isset($oldText[$i])) {
                 $this->_optionText[$i] = $oldText[$i];
             } else {
                 $this->_optionText[$i] = NULL;
             }
             if (isset($oldValues[$i])) {
                 $this->_optionValues[$i] = $oldValues[$i];
             } else {
                 $this->_optionValues[$i] = NULL;
             }
         }
     } else {
         if (sizeof($this->_optionText) > 0) {
             $loops = sizeof($this->_optionText);
         } else {
             return PHPWS_Error::get(PHATFORM_ZERO_OPTIONS, 'phatform', 'PHAT_Element::getOptions()');
         }
     }
     $elements[0] = '<input type="hidden" name="module" value="phatform" /><input type="hidden" name="PHAT_EL_OP" value="SaveElementOptions" />';
     if (PHAT_SHOW_INSTRUCTIONS) {
         $GLOBALS['CNT_phatform']['title'] = dgettext('phatform', 'Option Instructions');
     }
     $editTags['NUMBER_LABEL'] = dgettext('phatform', 'Option');
     $editTags['INPUT_LABEL'] = dgettext('phatform', 'Text');
     $editTags['VALUE_LABEL'] = dgettext('phatform', 'Value');
     $editTags['DEFAULT_LABEL'] = dgettext('phatform', 'Default');
     $editTags['OPTIONS'] = '';
     $rowClass = NULL;
     for ($i = 0; $i < $loops; $i++) {
         $optionRow['OPTION_NUMBER'] = $i + 1;
         $element = new Form_TextField("PHAT_ElementOptions[{$i}]", $this->_optionText[$i]);
         $element->setSize(PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
         $optionRow['OPTION_INPUT'] = $element->get();
         $element = new Form_TextField("PHAT_ElementValues[{$i}]", $this->_optionValues[$i]);
         $element->setSize(PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
         $optionRow['VALUE_INPUT'] = $element->get();
         $check = NULL;
         if ($className == 'PHAT_checkbox' || $className == 'PHAT_Multiselect') {
             if (isset($this->_optionValues[$i]) && (isset($this->_value[$i]) && $this->_optionValues[$i] == $this->_value[$i])) {
                 $check = $i;
             }
             $element = new Form_CheckBox("PHAT_ElementDefault[{$i}]", $i);
             $element->setMatch($check);
             $optionRow['OPTION_DEFAULT'] = $element->get();
         } else {
             if (isset($this->_optionValues[$i]) && $this->_optionValues[$i] == $this->_value) {
                 $check = $i;
             }
             $element = new Form_CheckBox('PHAT_ElementDefault', $i);
             $element->setMatch($check);
             $optionRow['OPTION_DEFAULT'] = $element->get();
         }
         $optionRow['ROW_CLASS'] = $rowClass;
         if ($i % 2) {
             $rowClass = ' class="bgcolor1"';
         } else {
             $rowClass = null;
         }
         $editTags['OPTIONS'] .= PHPWS_Template::processTemplate($optionRow, 'phatform', 'element/option.tpl');
     }
     $check = NULL;
     if ($this->getId()) {
         if ($this->_optionText == $this->_optionValues && sizeof($this->_optionText) > 0) {
             $check = 1;
         }
     }
     if (isset($_REQUEST['PHAT_SaveOptionSet'])) {
         $setName = $_REQUEST['PHAT_SaveOptionSet'];
     } else {
         $setName = NULL;
     }
     $element = new Form_Checkbox('PHAT_ElementUseText', 1);
     $element->setMatch($check);
     $editTags['USE_TEXT_CHECK'] = dgettext('phatform', 'Use option text as values') . ': ' . $element->get();
     $editTags['SAVE_OPTION_SET'] = dgettext('phatform', 'Save option set as') . ': ' . PHPWS_Form::formTextField('PHAT_SaveOptionSet', $setName, PHAT_DEFAULT_SIZE, PHAT_DEFAULT_MAXSIZE);
     $editTags['BACK_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Back'), 'PHAT_OptionBack');
     $editTags['SAVE_BUTTON'] = PHPWS_Form::formSubmit(dgettext('phatform', 'Save ' . $properName));
     $elements[0] .= PHPWS_Template::processTemplate($editTags, 'phatform', 'element/optionList.tpl');
     return PHPWS_Form::makeForm('PHAT_Options', 'index.php', $elements, 'post', NULL, NULL);
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: HaldunA/phpwebsite
 /**
  * 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 . '&amp;' . $op . '&amp;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;
 }