Esempio n. 1
0
function smarty_function_header($params, &$smarty)
{
    $self = $smarty->getTemplateVars('self');
    $theme = $smarty->getTemplateVars('theme');
    $title = $smarty->getTemplateVars('page_title');
    $inflector = new Inflector();
    $item_name = prettify($inflector->singularize($smarty->getTemplateVars('controller')));
    if (empty($title) || $title === 'Index') {
        switch ($smarty->getTemplateVars('action')) {
            case 'view':
                $title = $item_name . ' Details';
                break;
            case 'edit':
                $title = 'Editing ' . $item_name . ' Details';
                break;
            case 'new':
                $title = 'Create new ' . $item_name;
                break;
            case 'index':
            default:
                $title = $item_name;
                break;
        }
    }
    return '<h1 class="page_title">' . $title . '</h1>';
}
Esempio n. 2
0
 public function toHTML()
 {
     // change to facilitate lists
     $id = 'search_' . $this->fieldname;
     $name = 'Search[' . $this->fieldname . ']';
     if (count($this->options) > get_config('AUTOCOMPLETE_SELECT_LIMIT')) {
         $html = '';
         $selected = $this->value;
         if (empty($selected)) {
             $selected = $this->default;
         }
         $html .= '<input type="hidden" name="' . $name . '" id="' . $id . '" value="' . $selected . '" />';
         $text_value = isset($this->options[$selected]) ? $this->options[$selected] : '';
         $html .= '<input alt="Autocomplete enabled" type="text" id="' . $id . '_text" value="' . $text_value . '" class="uz-autocomplete  ui-autocomplete-input icon slim" data-id="' . $id . '" data-action="array"  />';
         $html .= '<script type="text/javascript">' . 'var ' . $id . '=' . json_encode(dataObject::toJSONArray($this->options)) . '</script>';
     } else {
         $html = '<select id="' . $id . '" name="' . $name . '">';
         foreach ($this->options as $val => $opt) {
             $selected = '';
             if ($this->value === "{$val}" || is_null($this->value) && $this->default === "{$val}") {
                 $selected = 'selected="selected"';
             }
             $html .= '<option value="' . $val . '" ' . $selected . '>' . h(prettify($opt)) . '</option>';
         }
         $html .= '</select></li>';
     }
     return $this->labelHTML() . $html;
 }
Esempio n. 3
0
function smarty_block_view_section($params, $content, &$smarty, $repeat)
{
    if (!empty($content)) {
        $attrs = array();
        $attrs['class'][] = 'heading';
        if (isset($params['class'])) {
            $attrs['class'][] = $params['class'];
        }
        if (isset($params['dont_prettify'])) {
            $heading = $params['heading'];
        } else {
            $heading = prettify($params['heading']);
        }
        if ($heading === 'EGS_HIDDEN_SECTION') {
            return '';
        }
        // convert attrs array to a string
        if (isset($params['expand'])) {
            $attrs['class'][] = 'expand';
            $attrs['class'][] = $params['expand'];
            $data['expand'] = $params['expand'] == 'closed' ? 'hidden' : '';
        }
        $data['attrs'] = build_attribute_string($attrs);
        $data['heading'] = $heading;
        $data['content'] = $content;
        // fetch smarty plugin template
        return smarty_plugin_template($smarty, $data, 'block.view_section');
    }
}
Esempio n. 4
0
 function getObjectPolicyValue()
 {
     $policy_detail = DataObjectFactory::Factory('SystemObjectPolicy');
     $policy_detail->load($this->object_policies_id);
     $policy_value = $policy_detail->getComponentTitle() . ' ' . prettify($policy_detail->get_field()) . ' ' . $policy_detail->getFormatted('operator') . ' ' . $policy_detail->getvalue();
     return $policy_value;
 }
Esempio n. 5
0
/**
 * Write a message to channel/user
 */
function sendMessage($socket, $channel, $msg)
{
    if (strlen($msg) > 2) {
        //Avoid sending empty lines to server, since all data should contain a line break, 2 chars is minimum
        $msg = prettify($msg);
        sendData($socket, "PRIVMSG {$channel} :{$msg}");
    }
}
Esempio n. 6
0
 function toSQL()
 {
     $sql = 'ALTER COLUMN ' . $this->name . ' ';
     foreach ($this->options->toArray() as $key => $val) {
         if ($val === true) {
             $sql .= prettify($key);
         }
     }
     return $sql;
 }
Esempio n. 7
0
 /**
  * @param void
  * @return string
  *
  * returns the HTML representation of the status checkboxes, each with a label
  * NOTE: This SearchField doesn't have an encompassing label, so will need to be considered should containing elements be required
  */
 public function toHTML()
 {
     $html = '';
     foreach ($this->statuses as $status) {
         $checked = '';
         if ($this->value_set && isset($this->value[$status]) || !$this->value_set && in_array($status, $this->default)) {
             $checked = 'checked="checked"';
         }
         $html .= '<label>' . prettify($status) . '</label><input type="checkbox" class="checkbox" name="Search[' . $this->fieldname . '][' . $status . ']" ' . $checked . '/>';
     }
     return $html;
 }
Esempio n. 8
0
 public function build($params, $data = false)
 {
     $script = '';
     $url = '?';
     $attrs = ' ';
     foreach ($params as $key => $val) {
         //special cases
         if (substr($key, 0, 1) === '_') {
             $attrs .= str_replace('_', '', $key) . '="' . $val . '" ';
             continue;
         }
         if ($key == 'value' || $key == 'img' || $key == 'alt') {
             continue;
         }
         //module and submodule
         if ($key == 'modules') {
             if (isset($val[0])) {
                 $url .= 'module=' . $val[0] . '&amp;';
                 //only allow submodule if module is set
                 if (isset($val[1])) {
                     $url .= 'submodule=' . $val[1] . '&amp;';
                 }
             }
             //everything else
         } else {
             $url .= strtolower($key) . '=' . urlencode($val) . '&amp;';
         }
     }
     //remove last ampersand
     $url = substr($url, 0, -5);
     $url = '/' . $url;
     if (isset($params['link'])) {
         $url = $params['link'];
     }
     if (empty($params['value'])) {
         $params['value'] = 'link';
     }
     if (isset($params['img'])) {
         $params['value'] = '<img src="' . $params['img'] . '" alt="' . $params['alt'] . '" />';
         $string = '<a ' . $attrs . ' href="' . $url . '">' . $params['value'] . '</a>';
     } else {
         if ($data) {
             $string = '<a ' . $attrs . ' href="' . $url . '">' . $params['value'] . '</a>';
         } else {
             $string = '<a ' . $attrs . ' href="' . $url . '">' . prettify($params['value']) . '</a>';
         }
     }
     return $string;
 }
Esempio n. 9
0
 public function toHTML()
 {
     $value = $this->value;
     if (!empty($value)) {
         $value['count'] = count($value['field']);
     } else {
         /*
          * if the array hasn't been sent, set the value to 1 
          * and set some dummy data (or perhaps test in the loop 
          * we need to set the loop at 1 to load the default single row.
          */
         $value = array('', '', '');
         //
         $value['count'] = 1;
     }
     $html .= '<dd><div id="matrix_' . $this->fieldname . '">';
     for ($i = 0; $i <= $value['count'] - 1; $i++) {
         // generate the matrix line
         $html .= '<p id="p:' . $this->fieldname . ':' . $i . '" class="matrix_field">';
         // generate the field selector
         $html .= '    <select style="clear: both;" id="search:' . $this->fieldname . ':field:' . $i . '" name="Search[' . $this->fieldname . '][field][]">';
         foreach ($this->options as $val => $opt) {
             $selected = '';
             if ($value['field'][$i] == $val || is_null($this->value) && $this->default == $val) {
                 $selected = 'selected="selected"';
             }
             $html .= '        <option value="' . $val . '" ' . $selected . '>' . h(prettify($opt)) . '</option>';
         }
         $html .= '    </select>';
         // generate the operator selector
         $html .= '    <select id="search:' . $this->fieldname . ':operator:' . $i . '" name="Search[' . $this->fieldname . '][operator][]">';
         foreach ($this->operators as $val => $opt) {
             $selected = '';
             if ($value['operator'][$i] == $val) {
                 $selected = 'selected="selected"';
             }
             $html .= '        <option value="' . $val . '" ' . $selected . '>' . h(prettify($opt)) . '</option>';
         }
         $html .= '    </select>';
         // generate the value input
         $html .= '    <input id="search:' . $this->fieldname . ':value:' . $i . '" type="text" name="Search[' . $this->fieldname . '][value][]" value="' . $value['value'][$i] . '" />';
         $html .= '	<a href="#" class="remove_matrix" id="search:' . $this->fieldname . ':delete:' . $i . '"><img src="' . THEME_URL . THEME . '/graphics/delete.png" /></a>';
         $html .= '</p>';
     }
     $html .= '</div>';
     $html .= '<p style="clear:both;"><a href="#" class="clone_matrix" rel="' . $this->fieldname . '"><img src="' . THEME_URL . THEME . '/graphics/add.png" style="float: left; margin-right: 5px;"/>Add a new constraint</a></p>';
     $html .= '</dd><br />';
     return $this->labelHTML() . $html;
 }
Esempio n. 10
0
 public function save_model($modelName, $dataIn = array(), &$errors = array(), &$warnings = array(), $duplicates = '')
 {
     // Need to define error array here due to too many nested levels
     $flash = Flash::Instance();
     $edi_errors = array();
     if ($duplicates != 'R') {
         // Do not reject duplicates - so check if record exists
         $model = new $modelName();
         $identifierFields = $model->getIdentifierFields();
         $identifierValues = array();
         foreach ($identifierFields as $key => $field) {
             if (isset($dataIn[$modelName][$field]) && $model->checkUniqueness($field)) {
                 $identifier_string = $field . ' : ' . $dataIn[$modelName][$field] . ',';
                 $identifierValues[$key] = $dataIn[$modelName][$field];
             } else {
                 unset($identifierFields[$key]);
             }
         }
         if (count($identifierFields) > 0 && count($identifierFields) == count($identifierValues)) {
             $model->loadBy($identifierFields, $identifierValues);
             if ($model->isLoaded()) {
                 if ($duplicates == 'I') {
                     // Ignore duplicates so return true
                     $warnings[] = 'Duplicate  ' . $identifier_string . ' Ignored';
                     return true;
                 } else {
                     // replace/update duplicate so set id field value
                     $dataIn[$modelName][$model->idField] = $model->{$model->idField};
                 }
             }
         }
     }
     $result = parent::save($modelName, $dataIn, $edi_errors);
     if (count($edi_errors) > 0) {
         // Add the Identifier Values to the errors to identify the data in error
         // Assumes the $dataIn array is an array of [ModelName][ModelData]
         // and that the input $modelName is the identifying model for the data
         $model = new $modelName();
         foreach ($model->getIdentifierFields() as $field) {
             $errors[] = prettify($field) . ' : ' . $dataIn[$modelName][$field];
         }
         $flash->addErrors($edi_errors);
         foreach ($edi_errors as $error) {
             $errors[] = $error;
         }
     }
     return $result;
 }
Esempio n. 11
0
 function addPlots($data)
 {
     $plots = array();
     $labels = array();
     $i = 0;
     foreach ($data as $key => $plot_data) {
         $plot = new BarPlot(array_values($plot_data));
         $plot->setLegend(prettify($key));
         $plot->setFillColor(self::$colours[$i]);
         $i++;
         $plots[] = $plot;
         $labels = array_merge($labels, array_keys($plot_data));
     }
     $group_plot = new GroupBarPlot($plots);
     $this->grapher->add($group_plot);
     $this->grapher->xaxis->setTickLabels($labels);
 }
Esempio n. 12
0
function smarty_function_eglet($params, &$smarty)
{
    $container = new EGletContainer();
    $eglet_name = $params['name'];
    $renderer = call_user_func(array($eglet_name, 'getRenderer'));
    $eglet = new $eglet_name($renderer);
    if (isset($params['title'])) {
        $title = $params['title'];
    } else {
        $title = prettify($params['name']);
    }
    $container->addEGlet($title, $eglet);
    if (isset($params['populate'])) {
        $container->populate();
        $container->render($params, $smarty);
    }
}
Esempio n. 13
0
 function __construct()
 {
     $this->css_title = empty($_SESSION['css']) ? $this->css : $_SESSION['css'];
     $this->css = 'styles/' . $this->css_title . '/' . $this->css_title . '.php';
     if ($_SERVER[QUERY_STRING]) {
         $query_string = htmlspecialchars(strip_tags($_SERVER[QUERY_STRING]));
         $crumbs = explode('/', $query_string);
         $bread = '?';
         foreach ($crumbs as $crumb) {
             $bread .= $crumb == '' ? 'index' : $crumb . '/';
             $breadcrumbs .= '<a href="' . $bread . '">' . prettify($crumb) . '</a> : ';
         }
         $this->breadcrumbs = '<a href="/" title="Home Page">Home</a> : ' . substr($breadcrumbs, 0, -2);
     } else {
         $this->breadcrumbs = '<a href="index.php" title="home page">home</a> : ';
     }
     $this->page = $_SERVER[SCRIPT_FILENAME];
     $this->pagetitle = prettify($crumb);
 }
Esempio n. 14
0
 function toSQL()
 {
     //username varchar not null primary key
     $sql = $this->name . ' ' . $this->type;
     foreach ($this->options as $key => $val) {
         $sql .= ' ' . prettify($key);
     }
     $refs = $this->references->toArray();
     if (count($refs) > 0) {
         $string = 'REFERENCES ' . $refs['table'] . '(' . $refs['column'] . ')';
         if (!empty($refs['on_update'])) {
             $string .= ' ON UPDATE ' . prettify($refs['on_update']);
         }
         if (!empty($refs['on_delete'])) {
             $string .= ' ON DELETE ' . prettify($refs['on_delete']);
         }
         $sql .= ' ' . $string;
     }
     return $sql;
 }
Esempio n. 15
0
function smarty_block_heading_cell($params, $content, &$smarty, $repeat)
{
    if (!empty($content)) {
        // why isn't this being done way sooner?!
        if (substr($params['field'], -2) == 'id') {
            return '';
        }
        // attribute variables
        $attrs = array();
        // merge data attributes with attributes array
        $attrs = array_merge($attrs, build_data_attributes($params));
        if ($smarty->getTemplateVars('no_ordering') !== TRUE) {
            $link = $smarty->getTemplateVars('self');
            $link['value'] = prettify($content);
            $action = $smarty->getTemplateVars('action');
            if (empty($action)) {
                $action = 'index';
            }
            $link['action'] = $action;
            if (isset($params['field'])) {
                $link['orderby'] = $params['field'];
                $attrs['data-column'] = $params['field'];
            }
            $content = link_to($link, $data = true);
            // WTF
        } else {
            $content = prettify($content);
        }
        $model = $params['model'];
        if ($model && $model->getField($params['field'])->type == 'numeric' || $params['field'] == 'right') {
            $attrs['class'][] = 'right';
        }
        if (isset($params['class'])) {
            $attrs['class'][] = $params['class'];
        }
        // build the attribute string based on the attribute array
        $attrs = build_attribute_string($attrs);
        // return the built string
        return '<th ' . $attrs . '>' . $content . '</th>' . "\n";
    }
}
Esempio n. 16
0
 function enable(&$errors = array(), $menu_options = array())
 {
     $position = Permission::getNextPosition();
     if (!$position) {
         $position = 0;
     }
     $data = array('permission' => $this->name, 'type' => 'm', 'description' => $this->description, 'title' => prettify($this->name), 'display' => true, 'position' => $position + 1);
     $m_parent_id = $this->addPermission($data, $errors);
     if (!$m_parent_id) {
         return false;
     }
     $c_position = 1;
     foreach ($this->module_components as $component) {
         switch ($component->type) {
             case 'C':
                 $name = str_replace('controller', '', strtolower($component->name));
                 if (isset($menu_options[$name])) {
                     $new_menu = $menu_options[$name];
                     $data = array('permission' => $new_menu['permission'], 'type' => 'c', 'description' => '', 'title' => $new_menu['title'], 'display' => $new_menu['display'], 'position' => $c_position++, 'parent_id' => $m_parent_id);
                     $c_parent_id = $this->addPermission($data, $errors);
                     if (!$c_parent_id) {
                         return false;
                     } else {
                         foreach ($new_menu['actions'] as $a_position => $action) {
                             $data = $action;
                             $data['type'] = 'a';
                             $data['position'] = $a_position + 1;
                             $data['parent_id'] = $c_parent_id;
                             if (!$this->addPermission($data, $errors)) {
                                 return false;
                             }
                         }
                     }
                 }
                 break;
         }
     }
     return $this->update($this->id, 'enabled', true);
 }
Esempio n. 17
0
 function translate($string)
 {
     // return, if set, the acronym for a string
     if (isset($this->acronyms[strtolower($string)])) {
         return $this->acronyms[strtolower($string)];
     }
     // return, if set, the over ride for a string
     if (isset($this->over_ride[strtolower($string)])) {
         return prettify($this->over_ride[strtolower($string)]);
     }
     // capatilse, replace "_" with " " and remove "_id" at end of string, apply this to $string
     $string = substr($string, -3) == '_id' ? substr($string, 0, -3) : $string;
     $string = ucwords(str_replace('_', ' ', $string));
     /*
      * Because some words may not exist atomically (such as the word CRM might) 
      * we need to find specific words and replace them with their known output, 
      * such as Uzlet -> uzLET	
      */
     foreach ($this->known_replacements as $find => $replace) {
         $string = str_ireplace($find, $replace, $string);
     }
     // return the prettified word
     return $string;
 }
Esempio n. 18
0
 function __construct($tablename = 'person')
 {
     // Register non-persistent attributes
     // Contruct the object
     parent::__construct($tablename);
     // Set specific characteristics
     $this->idField = 'id';
     $this->subClass = true;
     $this->fkField = 'party_id';
     $this->orderby = array('surname', 'firstname');
     $this->identifier = 'surname';
     $this->identifierField = 'firstname || \' \' || surname';
     $this->identifierFieldJoin = ', ';
     // Define relationships
     $this->hasMany('PartyContactMethod', 'contactmethods', 'party_id', 'party_id', null, TRUE);
     $this->hasMany('PartyAddress', 'addresses', 'party_id', 'party_id', null, TRUE);
     $this->hasMany('PartyAddress', 'mainaddress', 'party_id', 'party_id');
     $this->belongsTo('Company', 'company_id', 'company');
     $this->belongsTo('User', 'alteredby', 'last_altered_by');
     $this->belongsTo('User', 'assigned_to', 'person_assigned_to');
     $this->hasOne('Party', 'party_id', 'party');
     $this->hasOne('Company', 'company_id', 'companydetail');
     $this->actsAsTree('reports_to');
     $this->belongsTo('Person', 'reports_to', 'person_reports_to', null, 'surname || \', \' || firstname');
     $this->belongsTo('Language', 'lang', 'language');
     $this->setConcatenation('fullname', array('title', 'firstname', 'middlename', 'surname', 'suffix'));
     $this->setConcatenation('titlename', array('title', 'firstname', 'surname'));
     $this->hasMany('Opportunity', 'opportunities');
     $this->hasMany('Project', 'projects');
     $this->hasMany('Activity', 'activities');
     // Define field formats
     $this->getField('jobtitle')->tag = prettify('job_title');
     // Define validation
     // Define default values
     // Define enumerated types
 }
Esempio n. 19
0
function mktree($items, $checked = array(), $admins, $setall = FALSE, $adchild = FALSE)
{
    $html = '';
    $mod = '';
    if (isset($checked[$items['id']]) || $setall) {
        $mod = ' CHECKED ';
    }
    /****
     * If the item has children, we need to create the checkboxes for them by calling the mktree function on each of them
     * If not, just return a single checkbox.
     */
    if (!empty($items['children'])) {
        $html .= '<li class="' . $items['type'] . '">';
        if (trim($items['type']) == 'm' && !$adchild) {
            if (isset($admins[$items['permission']])) {
                $adcheck = 'checked';
            }
            $html .= '<input class="checkbox" type=checkbox name="admin[' . $items['permission'] . ']" value="admin' . $items['id'] . '" ' . $adcheck . ' /> ';
        }
        $html .= '<input class="checkbox" type=checkbox name="permission[' . $items['id'] . ']" value="' . $items['id'] . '"' . $mod . ' /> ' . prettify($items['permission']) . ": " . $items['description'] . '<ul class="permission">';
        foreach ($items['children'] as $child) {
            $html .= mktree($child, $checked, $admins, $setall, TRUE);
        }
        $html .= '</ul></li>';
    } else {
        $html .= '<li class="' . $items['type'] . '">';
        if (trim($items['type']) == 'm' && !$adchild) {
            if (isset($admins[$items['permission']])) {
                $adcheck = 'checked';
            }
            $html .= '<input class="checkbox" type=checkbox name="admin[' . $items['permission'] . ']" value="admin' . $items['id'] . '" ' . $adcheck . ' /> ';
        }
        $html .= '<input class="checkbox"  type=checkbox name="permission[' . $items['id'] . ']" value="' . $items['id'] . '"' . $mod . ' /> ' . prettify($items['permission']) . ': ' . $items['description'] . '</li>';
    }
    return $html;
}
Esempio n. 20
0
function smarty_function_datetime($params, &$smarty)
{
    $with =& $smarty->getTemplateVars('with');
    $data['display_tags'] = FALSE;
    $data['display_tags'] = !isset($params['notags']);
    $data['label']['value'] = prettify(isset($params['attribute']) ? $params['attribute'] : '');
    if (!empty($params['model'])) {
        $model =& $params['model'];
    } else {
        $model = $with['model'];
    }
    if (!empty($params['readonly']) && $params['readonly']) {
        $data['date']['attrs']['readonly'] = $params['readonly'];
        $data['hour']['attrs']['readonly'] = $params['readonly'];
        $data['minute']['attrs']['readonly'] = $params['readonly'];
        $data['date']['additional_class'] = '';
    } else {
        $data['date']['additional_class'] = 'datefield';
    }
    $controller_data =& $smarty->getTemplateVars('controller_data');
    #	$html = <<<EOT
    #<input type="text" name="%s" id="%s" class="icon date slim datefield%s" value="%s"/>&nbsp;
    #<input type="text" name="%s" id="%s" class="timefield" value="%s" />:<input type="text" name="%s" id="%s" class="timefield" value="%s" />
    #EOT;
    $basename = $params['attribute'];
    $model_name = get_class($model);
    $field = $model->getField($basename);
    $data['date']['attrs']['type'] = 'text';
    $data['hour']['attrs']['type'] = 'text';
    $data['minute']['attrs']['type'] = 'text';
    $data['date']['attrs']['name'] = $model_name . '[' . $basename . ']';
    $data['hour']['attrs']['name'] = $model_name . '[' . $basename . '_hours]';
    $data['minute']['attrs']['name'] = $model_name . '[' . $basename . '_minutes]';
    $data['date']['attrs']['id'] = strtolower($model_name . '_' . $basename);
    $data['hour']['attrs']['id'] = strtolower($model_name . '_' . $basename . '_hours');
    $data['minute']['attrs']['id'] = strtolower($model_name . '_' . $basename . '_minutes');
    $data['label']['for'] = $data['date']['attrs']['id'];
    $hidden = FALSE;
    require_once __DIR__ . '/function.sessionvalue.php';
    $start_date = smarty_function_sessionvalue($params, $model_name, $basename);
    $start_date_hour = smarty_function_sessionvalue($params, $model_name, $basename . '_hours');
    $start_date_minute = smarty_function_sessionvalue($params, $model_name, $basename . '_minutes');
    if (!empty($start_date)) {
        $value = $start_date;
        $value .= ' ' . (empty($start_date_hour) ? '00' : $start_date_hour);
        $value .= ':' . (empty($start_date_minute) ? '00' : $start_date_minute);
    }
    if (isset($controller_data[$basename])) {
        $hidden = TRUE;
        $value = $controller_data[$basename];
    } elseif (empty($value)) {
        $value = $field->value;
        if (empty($value) && !empty($params['value'])) {
            $value = $params['value'];
        }
        if (empty($value) && $field->has_default == 1) {
            $value = date(DATE_TIME_FORMAT, $field->default_value);
        }
        $data['label']['value'] = $field->tag;
        if ($field->not_null == 1) {
            $data['label']['value'] .= '*';
            $data['date']['additional_class'] .= ' required';
        }
    }
    $data['label']['value'] = isset($params['label']) ? $params['label'] : $data['label']['value'];
    if (!empty($value)) {
        $format = format_for_strptime(DATE_TIME_FORMAT);
        if (strptime($value, $format) !== FALSE) {
            $date_value = array_shift(explode(' ', $value));
            $hour_value = array_shift(explode(':', array_pop(explode(' ', $value))));
            $minute_value = array_pop(explode(':', array_pop(explode(' ', $value))));
        } else {
            list($date_value, $rest) = explode(' ', $value, 2);
            $date_value = date(DATE_FORMAT, strtotime($date_value));
            list($hour_value, $minute_value) = explode(':', $rest);
        }
        $data['date']['attrs']['value'] = $date_value;
        $data['hour']['attrs']['value'] = $hour_value;
        $data['minute']['attrs']['value'] = $minute_value;
    }
    if ($hidden) {
        $data['date']['attrs']['type'] = 'hidden';
        $data['hour']['attrs']['type'] = 'hidden';
        $data['minute']['attrs']['type'] = 'hidden';
    }
    foreach (array('date', 'hour', 'minute') as $type) {
        $data[$type]['attrs'] = build_attribute_string($data[$type]['attrs']);
    }
    return smarty_plugin_template($smarty, $data, 'function.datetime');
}
Esempio n. 21
0
function show_register($d)
{
    global $dir, $files, $cats, $names, $PAGE, $DATA, $this_page, $link;
    $d = "{$dir}/regmem{$d}.xml";
    if (!in_array($d, $files)) {
        $d = $files[0];
    }
    $d_iso = preg_replace("#{$dir}/regmem(.*?)\\.xml#", '$1', $d);
    $d_pretty = format_date($d_iso, LONGDATEFORMAT);
    $d = file_get_contents($d);
    $data = array();
    parse_file($d, 'only', $data);
    $this_page = 'regmem_date';
    $DATA->set_page_metadata($this_page, 'heading', "The Register of Members' Interests, {$d_pretty}");
    $PAGE->stripe_start();
    print $link;
    ?>
<p>This page shows the Register of Members' Interests as released on <?php 
    echo $d_pretty;
    ?>
, in alphabetical order by MP.
<?php 
    if ($d_iso > '2002-05-14') {
        ?>
<a href="./?f=<?php 
        echo $d_iso;
        ?>
">Compare this edition with the one before it</a></p><?php 
    }
    ?>
<div id="regmem">
<?php 
    uksort($data, 'by_name_ref');
    foreach ($data as $person_id => $v) {
        $out = '';
        foreach ($v as $cat_type => $vv) {
            $out .= cat_heading($cat_type, false);
            $d = array_key_exists('only', $data[$person_id][$cat_type]) ? $data[$person_id][$cat_type]['only'] : '';
            $out .= prettify($d) . "\n";
        }
        if ($out) {
            print '<div class="block">';
            print '<h2><a name="' . $person_id . '"></a>' . $names[$person_id] . ' - ';
            print '<a href="?p=' . $person_id . '">Register history</a> | ';
            print '<a href="http://www.theyworkforyou.com/mp/?pid=' . $person_id . '">MP\'s page</a>';
            print '</h2> <div class="blockbody">';
            print "\n{$out}";
            print '</div></div>';
        }
    }
    print '</div>';
}
Esempio n. 22
0
function prettify($name)
{
    return str_replace(' ', '-', ucwords(str_replace('_', ' ', str_replace('http_', '', strtolower($name)))));
}
$beaconFilename = sys_get_temp_dir() . "/beacon" . (isset($_REQUEST['name']) ? $_REQUEST['name'] : "") . ".txt";
$beaconFile = fopen($beaconFilename . ".tmp", 'w');
$httpHeaders = $_SERVER;
ksort($httpHeaders, SORT_STRING);
$contentType = "";
foreach ($httpHeaders as $name => $value) {
    if ($name === "CONTENT_TYPE" || $name === "HTTP_REFERER" || $name === "REQUEST_METHOD" || $name === "HTTP_COOKIE" || $name === "HTTP_ORIGIN") {
        if ($name === "CONTENT_TYPE") {
            $contentType = $value;
            $value = preg_replace('/boundary=.*$/', '', $value);
        }
        $headerName = prettify($name);
        fwrite($beaconFile, "{$headerName}: {$value}\n");
    }
}
$postdata = file_get_contents("php://input");
if (strlen($postdata) == 0) {
    $postdata = http_build_query($_POST);
}
fwrite($beaconFile, "Length: " . strlen($postdata) . "\n");
if (strpos($contentType, "application/") !== false) {
    $postdata = base64_encode($postdata);
}
fwrite($beaconFile, "Body: {$postdata}\n");
fclose($beaconFile);
rename($beaconFilename . ".tmp", $beaconFilename);
if (!array_key_exists('dontclearcookies', $_GET)) {
Esempio n. 23
0
    //remove semicolon (alternatively, set allow semi to true in bob's function)
    $query .= ' ' . $offset . ', ' . $limit;
    ?>
<h1>Samuel William Reinhardt</h1>
<h2>CS148 - Assignment3.0 - <?php 
    echo strtoupper($number);
    ?>
 Output </h2>      
<p> 	Using the following query...

	<?php 
    $values = array($offset, $limit);
    $counts = countify($query);
    $results = $thisDatabaseReader->select($query, $values, $counts['where'], $counts['condition'], $counts['quote'], $counts['symbol'], false, false, true);
    //running     capitalized code so that table headers aren't chopped oddly if they aren't given aliases
    $prettyCode = prettify($query);
    //wrap reserved in span
    ?>
	<code><?php 
    echo $prettyCode;
    ?>
<span class='sql-reserved'>;</span></code>
	... we are given the below table, with <?php 
    echo count($results);
    ?>
 rows.
	<div class='table-wrap-x'>
	<div class='table-wrap-y'> <!-- this may seem insane, but need for sensical scrollbars on the table. -->
	<table class='table special'>
		<tr class='table-row'>
		 <?php 
Esempio n. 24
0
 public function save_preferences()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $user = $this->_uses[$this->modeltype];
     $classname = ucfirst($this->_data['__moduleName']) . 'Preferences';
     $module = new $classname(true, 'ManagedUserPreferences', $user->username);
     $preferenceNames = $module->getPreferenceNames();
     $flash = Flash::Instance();
     $userPreferences = ManagedUserPreferences::instance($username);
     // FIXME: Validate incomming data against supplied values
     foreach ($preferenceNames as $preferenceName) {
         if (isset($this->_data[$preferenceName])) {
             $pref = $module->getPreference($preferenceName);
             if (isset($pref['type']) && $pref['type'] == 'numeric') {
                 if (!is_numeric($this->_data[$preferenceName])) {
                     $flash->addError($pref['display_name'] . ' must be numeric');
                     continue;
                 }
             }
             $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], $this->_data[$preferenceName]);
         } else {
             $preference = $module->getPreference($preferenceName);
             switch ($preference['type']) {
                 case 'checkbox':
                     $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], 'off');
                     break;
                 case 'select_multiple':
                     $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], array());
                     break;
             }
         }
     }
     $handled = $module->getHandledPreferences();
     foreach ($handled as $name => $preference) {
         if (!empty($this->_data[$name]) && isset($preference['callback'])) {
             $callback = array($module, $preference['callback']);
             call_user_func($callback, $this->_data);
         }
     }
     // Do stuff.
     if (!is_null($user->person)) {
         $name = $user->person;
     } else {
         $name = $user->username;
     }
     $flash->addMessage(prettify($this->_data['__moduleName']) . ' preferences for ' . $name . ' saved successfully');
     sendTo($this->name, 'index', $this->_modules);
 }
Esempio n. 25
0
function smarty_function_interval($params, &$smarty)
{
    $with =& $smarty->getTemplateVars('with');
    $data = array('class' => array());
    if (!empty($params['model'])) {
        $model =& $params['model'];
    } else {
        $model = $with['model'];
    }
    if (!empty($params['readonly']) && $params['readonly']) {
        $data['attrs']['readonly'] = $params['readonly'];
    }
    $controller_data =& $smarty->getTemplateVars('controller_data');
    $modelname = get_class($model);
    $basename = $params['attribute'];
    $unitname = $basename . '_unit';
    $name = $modelname . '[' . $basename . ']';
    $field = $model->getField($basename);
    if (isset($params['postfix'])) {
        $name .= $params['postfix'];
    }
    $data['select_name'] = $modelname . '[' . $unitname . ']';
    if (isset($params['postfix'])) {
        $data['select_name'] .= $params['postfix'];
    }
    $data['attrs']['id'] = strtolower($modelname) . '_' . $basename;
    $data['attrs']['name'] = $name;
    $data['label']['attrs']['for'] = strtolower($modelname) . '_' . $basename;
    $data['label']['value'] = $field->tag;
    $data['hidden'] = FALSE;
    $data['hours_selected'] = '';
    $data['days_selected'] = '';
    if (isset($params['value'])) {
        $data['attrs']['value'] = $params['value'];
    } elseif (isset($controller_data[$basename])) {
        $data['attrs']['value'] = $controller_data[$basename];
        $data['hidden'] = TRUE;
    } elseif (isset($_POST[$modelname][$basename])) {
        $data['attrs']['value'] = $_POST[$modelname][$basename];
    } elseif (!empty($params['group']) && isset($_POST[$params['group']][$modelname][$basename])) {
        $data['attrs']['value'] = $_POST[$params['group']][$modelname][$basename];
    } elseif (!empty($params['number']) && isset($_POST[$modelname][$params['number']][$basename])) {
        $data['attrs']['value'] = $_POST[$modelname][$params['number']][$basename];
    } elseif (isset($_SESSION['_controller_data'][$modelname][$basename])) {
        $data['attrs']['value'] = $_SESSION['_controller_data'][$modelname][$basename];
    } else {
        $data['attrs']['value'] = $field->value;
    }
    if (isset($_POST[$modelname][$unitname])) {
        $units = $_POST[$modelname][$unitname];
    } elseif (!empty($params['group']) && isset($_POST[$params['group']][$modelname][$unitname])) {
        $units = $_POST[$params['group']][$modelname][$unitname];
    } elseif (!empty($params['number']) && isset($_POST[$modelname][$params['number']][$unitname])) {
        $units = $_POST[$modelname][$params['number']][$unitname];
    } elseif (isset($_SESSION['_controller_data'][$modelname][$unitname])) {
        $units = $_SESSION['_controller_data'][$modelname][$unitname];
    } else {
        $units = 'hours';
    }
    $data['days_label'] = prettify('days');
    $data['hours_label'] = prettify('hours');
    $data['minutes_label'] = prettify('minutes');
    if (!isset($data['attrs']['value']) && $field->has_default == 1) {
        $data['attrs']['value'] = $field->default_value;
    }
    if (!empty($data['attrs']['value'])) {
        if (is_array($data['attrs']['value'])) {
            $units = $data['attrs']['value'][1];
            $data['attrs']['value'] = $data['attrs']['value'][0];
        } else {
            // ATTN: setting units twice?
            $data['attrs']['value'] = to_working_days($data['attrs']['value'], false);
            $data['attrs']['value'] = $data['attrs']['value'] * SystemCompanySettings::DAY_LENGTH;
        }
        $data[$units . '_selected'] = 'selected="selected"';
    }
    // processing over, collect vars
    // ATTN: should the above be $value, then converted to $data['attrs']['value']?
    if ($hidden) {
        if (isset($days_selected)) {
            $data['unit_value'] = 'days';
        } else {
            $data['unit_value'] = 'hours';
        }
    }
    $data['class'] = implode(' ', $data['class']);
    // convert attrs array to a string
    $data['attrs'] = build_attribute_string($data['attrs']);
    $data['label']['attrs'] = build_attribute_string($data['label']['attrs']);
    // fetch smarty plugin template
    return smarty_plugin_template($smarty, $data, 'function.interval');
}
Esempio n. 26
0
 /**
  * @param void
  * @return string
  *
  * Returns the HTML string containing the field's <label> tag.
  * NOTE: at some point, this might end up being called from BaseSearch's toHTML to allow for containing elements
  */
 protected function labelHTML()
 {
     $html = '<li><label for="search_' . str_replace('/', '_', $this->fieldname) . '">' . prettify($this->label) . '</label>';
     return $html;
 }
Esempio n. 27
0
 private function newModel($dataset)
 {
     $model = new DataObject($this->getTablename($dataset->name));
     $model->setTitle(prettify($dataset->name));
     $display_fields = array();
     // Clear the cached fields to make sure we get the latest
     $dataset->clear('fields');
     // Need to load FK definitions
     foreach ($dataset->fields as $field) {
         if (!is_null($field->module_component_id)) {
             if (substr($field->name, -3) == '_id') {
                 $name = str_replace('_id', '', $field->name);
             } else {
                 $name = strtolower(str_replace(' ', '_', $field->title));
             }
             $model->belongsTo($field->fk_link, $field->name, $name);
         } else {
             $name = $field->name;
         }
         if ($field->display_in_list == 't') {
             $display_fields[$name] = $field->title;
         }
         // Note: DataObject::getFields does a sort into alphabetic field name order
         // which was required to dislpay the field list in alphabetic order when looking
         // at DataObject model components - need to get the order of fields from the
         // dataset fields definition (ordered on popsition) so store in the dataset
         // $_fields private array here. Also, the field title is only added to DataObject
         // display fields and we need the title as the field label on the edit data form.
         $this->_fields[$field->name] = $field->title;
     }
     if (!empty($display_fields)) {
         $model->setDisplayFields($model->setDefaultDisplayFields($display_fields));
     }
     return $model;
 }
Esempio n. 28
0
 function getOrderItemSummary($period, $type = '', $page = '', $perpage = '')
 {
     $sh = new SearchHandler($this, false);
     if ($type != '') {
         $sh->addConstraint(new Constraint('type', '=', $type));
     }
     if (!empty($page)) {
         if (empty($perpage)) {
             $perpage = 9;
         }
         $sh->setLimit($perpage, ($page - 1) * $perpage);
         $sh->perpage = $perpage;
     }
     $fields = array('stitem');
     $sh->setGroupBy($fields);
     $sh->setOrderby($fields);
     $fields[] = 'sum(os_qty) as qty';
     $fields[] = 'sum(base_net_value) as value';
     $sh->setFields($fields);
     $sh->addConstraint(new Constraint('status', 'in', "('N', 'R', 'S')"));
     $today = fix_date(date(DATE_FORMAT));
     $currentmonthstart = fix_date('01/' . date('m/Y'));
     switch (prettify($period)) {
         case 'Overdue':
             $startdate = fix_date('01/01/1970');
             $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime($today))));
             break;
         case 'Today':
             $startdate = $today;
             $enddate = $today;
             break;
         case 'This Week':
             $startdate = fix_date(date(DATE_FORMAT, strtotime("+1 days", strtotime($today))));
             $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("next Monday", strtotime($today)))));
             break;
         case 'This Month':
             $startdate = fix_date(date(DATE_FORMAT, strtotime("next Monday", strtotime($today))));
             $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("+1 months", strtotime($currentmonthstart)))));
             break;
         case 'Next Month':
             $startdate = fix_date(date(DATE_FORMAT, strtotime("+1 months", strtotime($currentmonthstart))));
             $enddate = fix_date(date(DATE_FORMAT, strtotime("-1 day", strtotime("+2 months", strtotime($currentmonthstart)))));
             break;
     }
     $sh->addConstraint(new Constraint('due_despatch_date', 'between', "'" . $startdate . "' and '" . $enddate . "'"));
     $this->load($sh);
     // Construct dynamic title ('Orders', 'Quotes', default)
     if ($type == 'O') {
         $this->customersales = array('title' => 'Orders, ' . prettify($period), 'items' => array());
     } elseif ($type == 'Q') {
         $this->customersales = array('title' => 'Quotes, ' . prettify($period), 'items' => array());
     } else {
         $this->customersales = array('title' => prettify($period), 'items' => array());
     }
     foreach ($this as $order) {
         $this->customersales['items'][$order->id]['value'] = $order->value;
         $this->customersales['items'][$order->id]['qty'] = $order->qty;
     }
     $this->customersales['page'] = $page;
     $this->customersales['perpage'] = $perpage;
     $this->customersales['num_pages'] = $this->num_pages == 0 ? 1 : $this->num_pages;
     $this->customersales['period'] = $period;
     $this->customersales['type'] = $type;
     $this->customersales['controller'] = 'Sorders';
     return $this->customersales;
 }
Esempio n. 29
0
 /**
  * @param void
  * @return string
  *
  * Returns the HTML string containing the field's <label> tag.
  * NOTE: at some point, this might end up being called from BaseSearch's toHTML to allow for containing elements
  */
 protected function labelHTML()
 {
     // change to facilitate sortable fields
     $html = '<li><label for="search_' . str_replace('/', '_', $this->fieldname) . '">' . prettify($this->label) . '</label>';
     return $html;
 }
Esempio n. 30
0
 public function save()
 {
     $module = $this->getPreferenceClass($this->_data['__moduleName']);
     $preferenceNames = $module->getPreferenceNames();
     $flash = Flash::Instance();
     $userPreferences = UserPreferences::instance();
     // FIXME: Validate incomming data against supplied values
     foreach ($preferenceNames as $preferenceName) {
         if (isset($this->_data[$preferenceName])) {
             $pref = $module->getPreference($preferenceName);
             if (isset($pref['type']) && $pref['type'] == 'numeric') {
                 if (!is_numeric($this->_data[$preferenceName])) {
                     $flash->addError($pref['display_name'] . ' must be numeric');
                     continue;
                 }
             }
             $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], $this->_data[$preferenceName]);
         } else {
             $preference = $module->getPreference($preferenceName);
             switch ($preference['type']) {
                 case 'checkbox':
                     $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], 'off');
                     break;
                 case 'select_multiple':
                     $userPreferences->setPreferenceValue($preferenceName, $this->_data['__moduleName'], array());
                     break;
             }
         }
     }
     $handled = $module->getHandledPreferences();
     foreach ($handled as $name => $preference) {
         if (!empty($this->_data[$name]) && isset($preference['callback'])) {
             $callback = array($module, $preference['callback']);
             call_user_func($callback, $this->_data);
         }
     }
     // Do stuff.
     $flash->addMessage(prettify($this->_data['__moduleName']) . ' preferences saved successfully');
     sendTo('', '', $this->_modules);
 }