/**
 * Smarty ModuleNavigation
 * Displays a Module Navigation Element
 * depends on module configuration file.
 *
 * Examples:
 * <pre>
 * {modulnavigation}
 * </pre>
 *
 * Type:     function<br>
 * Name:     modulenavigation<br>
 * Purpose:  display modulenavigation<br>
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_modulenavigation($params, $smarty)
{
    $module = Koch_HttpRequest::getRoute()->getModuleName();
    $file = ROOT_MOD . $module . DIRECTORY_SEPARATOR . $module . '.menu.php';
    if (is_file($file)) {
        // this includes the file, which contains a php array name $modulenavigation
        include $file;
        // push the $modulenavigation array to a callback function
        // for further processing of the menu items
        $modulenavigation = array_map("applyCallbacks", $modulenavigation);
        $smarty->assign('modulenavigation', $modulenavigation);
        // The file is located in clansuite/themes/core/view/smarty/modulenavigation-generic.tpl
        return $smarty->fetch('modulenavigation-generic.tpl');
    } else {
        // the module menu navigation file is missing
        $smarty->assign('modulename', $module);
        $errormessage = $smarty->fetch('modulenavigation_not_found.tpl');
        trigger_error($errormessage);
    }
}
Ejemplo n.º 2
0
 /**
  * Set Values to Form
  *
  * An associative array is used to pre-populate form elements.
  * The keys of this array correspond with the element names.
  *
  * There are two use cases for this method:
  * 1) pre-filled form
  *    Some default values are set to the form, which then get altered by the user.
  * b) incomming post data
  *    Set the incomming POST data values are set to the form for validation.
  *
  * @param object|array $data Object or Array. If null (default), POST parameters are used.
  */
 public function setValues($data = null)
 {
     // because $data might be an object, typecast $data object to array
     if (is_object($data) === true) {
         $data = (array) $data;
     } elseif (null === $data) {
         if ('POST' === Koch_HttpRequest::getRequestMethod()) {
             $data = Koch_HttpRequest::getPost();
         }
     }
     // now we got an $data array to populate all the formelements with (setValue)
     foreach ($data as $key => $value) {
         foreach ($this->formelements as $formelement) {
             $type = $formelement->getType();
             /**
              * Exclude some formelements from setValue(), e.g. buttons, etc.
              * Setting the value would just change the visible "name" of these elements.
              */
             if (true === in_array($type, array('submit', 'button', 'cancelbutton', 'resetbutton'))) {
                 continue;
             }
             // data[key] and formelement[name] have to match
             if ($formelement->getName() == ucfirst($key)) {
                 $formelement->setValue($value);
             }
         }
     }
 }