/**
 * Smarty {optiondisplayer} function plugin
 *
 * Type:     function<br>
 * Name:     optiondisplayer<br>
 * Purpose:  display option dropdown list
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_optiondisplayer($params, &$smarty)
{
    global $db;
    $groupname = $params['options'];
    $product = $params['product'];
    $display_price_as = isset($params['display_price_as']) ? $params['display_price_as'] : 'diff';
    // get the option group
    $og = new optiongroup();
    //$group = $og->find('bytitle', $groupname);
    $group = $og->find('first', 'product_id=' . $product->id . ' AND title="' . $groupname . '"');
    //grab the options configured for this product
    $options = $product->optionDropdown($group->title, $display_price_as);
    // if there are no  options we can return now
    if (empty($options)) {
        return false;
    }
    // find the default option if there is one.
    $default = $db->selectValue('option', 'id', 'optiongroup_id=' . $group->id . ' AND is_default=1');
    $view = $params['view'];
    //if((isset() || $og->required == false) $includeblank = $params['includeblank'] ;
    //elseif((isset($params['includeblank']) && $params['includeblank'] == false) || $og->required == true) $includeblank = false;
    $includeblank = $og->required == false && !isset($params['includeblank']) ? gt('-- Please Select an Option --') : $params['includeblank'];
    $template = get_common_template($view, $smarty->getTemplateVars('__loc'), 'options');
    $template->assign('product', $product);
    $template->assign('options', $options);
    $template->assign('group', $group);
    $template->assign('params', $params);
    $template->assign('default', $default);
    $template->assign('includeblank', $includeblank);
    $template->assign('required', $params['required']);
    $template->assign('selected', $params['selected']);
    echo $template->render();
}
/**
 * Smarty {filedisplayer} function plugin
 *
 * Type:     function<br>
 * Name:     filedisplayer<br>
 * Purpose:  display files
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_filedisplayer($params, &$smarty)
{
    $config = $smarty->getTemplateVars('config');
    // make sure we have a view, and files..otherwise return nada.
    if (empty($params['view']) || empty($params['files'])) {
        return "";
    }
    // get the view, pass params and render & return it.
    $view = isset($params['view']) ? $params['view'] : 'Downloadable Files';
    $title = isset($params['title']) ? $params['title'] : '';
    $badvals = array("[", "]", ",", " ", "'", "\"", "&", "#", "%", "@", "!", "\$", "(", ")", "{", "}");
    $config['uniqueid'] = str_replace($badvals, "", $smarty->getTemplateVars('__loc')->src) . $params['record']->id;
    if ($config['pio'] && $params['is_listing']) {
        $tmp = reset($params['files']);
        unset($params['files']);
        $params['files'][] = $tmp;
    }
    $float = $config['ffloat'] == "No Float" ? "" : "float:" . strtolower($config['ffloat']) . ";";
    $width = !empty($config['fwidth']) ? $config['fwidth'] : "200";
    switch ($config['ffloat']) {
        case 'Left':
            $margin = "margin-right:" . $config['fmargin'] . "px;";
            break;
        case 'Right':
            $margin = "margin-left:" . $config['fmargin'] . "px;";
            break;
        default:
            $margin = "";
            break;
    }
    $html = '<div class="display-files" style="' . $float . 'width:' . $width . 'px;' . $margin . '">';
    $template = get_common_template($view, $smarty->getTemplateVars('__loc'), 'file');
    $template->assign('files', $params['files']);
    $template->assign('style', $params['style']);
    $template->assign('config', $config);
    $template->assign('params', $params);
    $html .= $template->render();
    $html .= "</div>";
    echo $html;
}
예제 #3
0
 /**
  * expPaginator Constructor
  *
  * This is the main entry point for using the expPaginator.  See example above.
  *
  * @param array $params Use this to set any of the class variables. Ones not passed will be set to a default.
  * @return \expPaginator
  */
 public function __construct($params = array())
 {
     global $router, $db;
     $this->where = empty($params['where']) ? null : $params['where'];
     $this->records = empty($params['records']) ? array() : $params['records'];
     $this->limit = empty($params['limit']) ? 10 : $params['limit'];
     $this->page = empty($_REQUEST['page']) ? 1 : intval($_REQUEST['page']);
     $this->action = empty($params['action']) ? '' : $params['action'];
     $this->controller = empty($params['controller']) ? '' : $params['controller'];
     $this->sql = empty($params['sql']) ? '' : $params['sql'];
     $this->count_sql = empty($params['count_sql']) ? '' : $params['count_sql'];
     $this->order = empty($params['order']) ? 'id' : $params['order'];
     $this->dir = empty($params['dir']) ? 'ASC' : $params['dir'];
     $this->src = empty($params['src']) ? null : $params['src'];
     // if a view was passed we'll use it.
     if (isset($params['view'])) {
         $this->view = $params['view'];
     }
     // setup the model if one was passed.
     if (isset($params['model'])) {
         $this->model = $params['model'];
         $class = new $this->model(null, false, false);
     }
     // auto-include the CSS for pagination links
     expCSS::pushToHead(array("unique" => "pagination", "link" => PATH_RELATIVE . "framework/core/assets/css/pagination.css"));
     $this->start = $this->page * $this->limit - $this->limit;
     //setup the columns and default ordering of records
     if (isset($params['columns'])) {
         $this->columns = array();
         foreach ($params['columns'] as $key => $col) {
             $colparse[$key] = explode('|', $col);
             $column = array($key => $colparse[$key][0]);
             $this->columns = array_merge($this->columns, $column);
             if (!empty($colparse[$key][1])) {
                 $params = explode(',', $colparse[$key][1]);
                 foreach ($params as $paramval) {
                     $prm = explode('=', $paramval);
                     $this->linkables[$key][$prm[0]] = $prm[1];
                 }
             }
         }
     }
     // if we are in an action, see if the action if for this controller/action..if so pull the order
     // and order direction from the request params...this is how the params are passed via the column
     // headers.
     $this->order_direction = $this->dir;
     if (expTheme::inAction()) {
         //FIXME: module/controller glue code
         $mod = !empty($_REQUEST['controller']) ? $_REQUEST['controller'] : $_REQUEST['module'];
         //		    if ($this->controller == $mod && $this->action == $_REQUEST['action']) {
         $this->order = isset($_REQUEST['order']) ? $_REQUEST['order'] : $this->order;
         $this->order_direction = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : $this->dir;
         //			}
     }
     // figure out how many records we're dealing with & grab the records
     //if (!empty($this->records)) { //from Merge <~~ this doesn't work. Could be empty, but still need to hit.
     if (isset($params['records'])) {
         // if we pass $params['records'], we WANT to hit this
         // sort, count and slice the records that were passed in to us
         usort($this->records, array('expPaginator', strtolower($this->order_direction)));
         $this->total_records = count($this->records);
         if ($this->start > $this->total_records) {
             $this->start = $this->total_records - $this->limit;
         }
         $this->records = array_slice($this->records, $this->start, $this->limit);
     } elseif (!empty($class)) {
         //where clause     //FJD: was $this->class, but wasn't working...
         $this->total_records = $class->find('count', $this->where);
         $this->records = $class->find('all', $this->where, $this->order . ' ' . $this->order_direction, $this->limit, $this->start);
     } elseif (!empty($this->where)) {
         //from Merge....where clause
         $this->total_records = $class->find('count', $this->where);
         if ($this->start > $this->total_records) {
             $this->start = $this->total_records - $this->limit;
         }
         $this->records = $class->find('all', $this->where, $this->order . ' ' . $this->order_direction, $this->limit, $this->start);
     } else {
         //sql clause
         //$records = $db->selectObjectsBySql($this->sql);
         //$this->total_records = count($records);
         //this is MUCH faster if you supply a proper count_sql param using a COUNT() function; if not,
         //we'll run the standard sql and do a queryRows with it
         //$this->total_records = $this->count_sql == '' ? $db->queryRows($this->sql) : $db->selectValueBySql($this->count_sql); //From Merge
         $this->total_records = $db->countObjectsBySql($this->count_sql);
         //$db->queryRows($this->sql); //From most current Trunk
         if ($this->start > $this->total_records) {
             $this->start = $this->total_records - $this->limit;
         }
         if (!empty($this->order)) {
             $this->sql .= ' ORDER BY ' . $this->order . ' ' . $this->order_direction;
         }
         if (!empty($this->limit)) {
             $this->sql .= ' LIMIT ' . $this->start . ',' . $this->limit;
         }
         $this->records = array();
         if (isset($this->model) || isset($params['model_field'])) {
             foreach ($db->selectObjectsBySql($this->sql) as $record) {
                 $classname = isset($params['model_field']) ? $record->{$params}['model_field'] : $this->model;
                 //$this->records[] = new $classname($record->id, true, true); //From current trunk // added false, true, as we shouldn't need associated items here, but do need attached. FJD.
                 $this->records[] = new $classname($record->id, false, true);
                 //From Merge //added false, true, as we shouldn't need associated items here, but do need attached. FJD.
             }
         } else {
             $this->records = $db->selectObjectsBySql($this->sql);
         }
     }
     if (!isset($params['records'])) {
         $this->runCallback();
     }
     // isset($params['records']) added to correct search for products.
     //$this->runCallback();
     //eDebug($this->records);
     // get the number of the last record we are showing...this is used in the page links.
     // i.e.  "showing 10-19 of 57"...$this->last would be the 19 in that string
     if ($this->total_records > 0) {
         $this->firstrecord = $this->start + 1;
         $this->lastrecord = $this->total_records < $this->limit ? $this->start + $this->total_records : $this->start + $this->limit;
         if ($this->lastrecord > $this->total_records) {
             $this->lastrecord = $this->total_records;
         }
     } else {
         $this->firstrecord = 0;
         $this->lastrecord = 0;
     }
     // get the page parameters from the router to build the links
     //$page_params = $router->params; //from Current Trunk
     $page_params = $this->cleanParams($router->params);
     //From Merge
     //if (empty($page_params['module'])) $page_params['module'] = $this->controller;
     //if (empty($page_params['action'])) $page_params['action'] = $this->action;
     //if (empty($page_params['src']) && isset($params['src'])) $page_params['src'] = $params['src'];
     if (!empty($this->controller)) {
         unset($page_params['module']);
         $page_params['controller'] = str_replace("Controller", "", $this->controller);
     }
     if (!empty($this->action)) {
         $page_params['action'] = $this->action;
     }
     if (!empty($this->src)) {
         $page_params['src'] = $this->src;
     }
     if (isset($page_params['section'])) {
         unset($page_params['section']);
     }
     if (!empty($this->view)) {
         $page_params['view'] = $this->view;
     }
     //build out a couple links we can use in the views.
     $this->pagelink = $router->makeLink($page_params, null, null, true);
     // if don't have enough records for more than one page then we're done.
     //if ($this->total_records <= $this->limit) return true;
     $this->total_pages = $this->limit > 0 ? ceil($this->total_records / $this->limit) : 0;
     if ($this->page > $this->total_pages) {
         $this->page = $this->total_pages;
     }
     //setup the pages for the links
     if ($this->total_pages > $this->pages_to_show) {
         $this->first_pagelink = max(1, floor($this->page - $this->pages_to_show / 2));
         $this->last_pagelink = $this->first_pagelink + $this->pages_to_show - 1;
         if ($this->last_pagelink > $this->total_pages) {
             $this->first_pagelink = max(1, $this->total_pages - $this->pages_to_show);
             $this->last_pagelink = $this->total_pages;
         }
     } else {
         $this->first_pagelink = 1;
         $this->last_pagelink = $this->total_pages;
     }
     // setup the previous link
     if ($this->page > 1) {
         $page_params['page'] = $this->page - 1;
         $this->previous_page = $router->makeLink($page_params, null, null, true);
     }
     // setup the next link
     if ($this->page < $this->total_pages) {
         $page_params['page'] = $this->page + 1;
         $this->next_page = $router->makeLink($page_params, null, null, true);
     }
     // setup the previous 10 link
     if ($this->page > $this->pages_to_show) {
         $page_params['page'] = $this->first_pagelink - 1;
         $this->previous_shift = $router->makeLink($page_params, null, null, true);
         $page_params['page'] = 1;
         $this->firstpage = $router->makeLink($page_params, null, null, true);
     }
     // setup the next 10 link
     if ($this->page < $this->total_pages - $this->pages_to_show) {
         $page_params['page'] = $this->last_pagelink + 1;
         $this->next_shift = $router->makeLink($page_params, null, null, true);
         $page_params['page'] = $this->total_pages;
         $this->lastpage = $router->makeLink($page_params, null, null, true);
     }
     // setup the links to the pages being displayed.
     for ($i = $this->first_pagelink; $i <= $this->last_pagelink; $i++) {
         $page_params['page'] = $i;
         $this->pages[$i] = $router->makeLink($page_params, null, null, true);
     }
     $links_template = get_common_template('pagination_links', null, 'common');
     $links_template->assign('page', $this);
     $this->links = $links_template->render();
     $this->makeHeaderCols($page_params);
     $sortparams = array_merge($page_params, $router->params);
     //From Merge ****
     if (isset($router->params['page'])) {
         $sortparams['page'] = $router->params['page'];
     } else {
         unset($sortparams['page']);
     }
     //End From Merge ****
     $this->makeSortDropdown($sortparams);
     $table_template = get_common_template('pagination_table', null, 'common');
     $table_template->assign('page', $this);
     $this->table = $table_template->render();
 }