static function form($object = null) { $form = new form(); if (!isset($object->id)) { $object->name = ''; $object->active = 1; $object->public = 1; $object->subtheme = ''; $object->page_title = SITE_TITLE; $object->keywords = SITE_KEYWORDS; $object->description = SITE_DESCRIPTION; if (!isset($object->parent)) { $object->parent = 0; } // NOT IMPLEMENTED YET //$object->subtheme=''; } else { $form->meta('id', $object->id); } $form->meta('parent', $object->parent); $form->register('name', gt('Name'), new textcontrol($object->name)); if (!isset($object->id) && $object->parent != 0) { // Add the 'Add' drop down if not a top level global $db; $sections = $db->selectObjects('section_template', 'parent=' . $object->parent); if (count($sections)) { $sections = expSorter::sort(array('array' => $sections, 'sortby' => 'rank', 'order' => 'ASC')); $dd = array(gt('At the Top')); foreach ($sections as $s) { $dd[] = sprintf(gt('After') . " %s", $s->name); } $form->register('rank', gt('Position'), new dropdowncontrol(count($dd) - 1, $dd)); } else { $form->meta('rank', 0); } } else { $form->meta('rank', 0); } if (is_readable(THEME_ABSOLUTE . 'subthemes')) { // grab sub themes $form->register('subtheme', gt('Theme Variation'), new dropdowncontrol($object->subtheme, expTheme::getSubThemes())); } $form->register('active', gt('Active'), new checkboxcontrol($object->active)); $form->register('public', gt('Public'), new checkboxcontrol($object->public)); // Register the Page Meta Data controls. $form->register('page_title', gt('Page Title'), new textcontrol($object->page_title)); $form->register('keywords', gt('keywords'), new texteditorcontrol($object->keywords, 5, 25)); $form->register('description', gt('Page Description'), new texteditorcontrol($object->keywords, 5, 25)); $form->register('submit', '', new buttongroupcontrol(gt('Save'), '', gt('Cancel'))); return $form; }
/** exdoc * List Countries and Regions in the Geo Database. Returns a two-tiered array of countries and regions. * @node Subsystems:expGeo * @return array */ public static function listCountriesAndRegions() { global $db; $countries = array(); foreach ($db->selectObjects("geo_country") as $c) { $countries[$c->id] = null; $countries[$c->id]->name = $c->name; $countries[$c->id]->regions = array(); foreach ($db->selectObjects("geo_region", "country_id=" . $c->id) as $r) { $countries[$c->id]->regions[$r->id] = $r->name; } uasort($countries[$c->id]->regions, "strnatcasecmp"); } $countries = expSorter::sort(array('array' => $countries, 'sortby' => 'name', 'order' => 'ASC', 'ignore_case' => true, 'type' => 'a')); return $countries; }
function show($view, $loc = null, $title = '') { global $db; $question = $db->selectObject('poll_question', "is_active = 1 AND location_data='" . serialize($loc) . "'"); $answers = array(); if ($question) { $answers = $db->selectObjects('poll_answer', 'question_id=' . $question->id); } $answers = expSorter::sort(array('array' => $answers, 'sortby' => 'rank', 'order' => 'ASC')); $template = new template('simplepollmodule', $view, $loc); $template->assign('moduletitle', $title); $template->assign('question', $question); $template->assign('answers', $answers); $template->assign('have_answers', count($answers)); $template->register_permissions(array('administrate', 'configure', 'manage_question', 'manage_answer'), $loc); $template->output(); }
public function tags() { $blogs = $this->blog->find('all'); $used_tags = array(); foreach ($blogs as $blog) { foreach ($blog->expTag as $tag) { if (isset($used_tags[$tag->id])) { $used_tags[$tag->id]->count += 1; } else { $exptag = new expTag($tag->id); $used_tags[$tag->id] = $exptag; $used_tags[$tag->id]->count = 1; } } } $used_tags = expSorter::sort(array('array' => $used_tags, 'sortby' => 'title', 'order' => 'ASC', 'ignore_case' => true)); assign_to_template(array('tags' => $used_tags)); }
function _getEventsForDates($edates, $sort_asc = true) { global $db; $events = array(); foreach ($edates as $edate) { if (!isset($this->params['cat'])) { if (isset($this->params['title']) && is_string($this->params['title'])) { $default_id = $db->selectValue('storeCategories', 'id', "sef_url='" . $this->params['title'] . "'"); } elseif (!empty($this->config['category'])) { $default_id = $this->config['category']; } elseif (ecomconfig::getConfig('show_first_category')) { $default_id = $db->selectValue('storeCategories', 'id', 'lft=1'); } else { $default_id = 0; } } $parent = isset($this->params['cat']) ? intval($this->params['cat']) : $default_id; $category = new storeCategory($parent); $sql = 'SELECT DISTINCT p.*, er.event_starttime, er.signup_cutoff FROM ' . DB_TABLE_PREFIX . '_product p '; $sql .= 'JOIN ' . DB_TABLE_PREFIX . '_product_storeCategories sc ON p.id = sc.product_id '; $sql .= 'JOIN ' . DB_TABLE_PREFIX . '_eventregistration er ON p.product_type_id = er.id '; $sql .= 'WHERE sc.storecategories_id IN ('; $sql .= 'SELECT id FROM exponent_storeCategories WHERE rgt BETWEEN ' . $category->lft . ' AND ' . $category->rgt . ')'; if ($category->hide_closed_events) { $sql .= ' AND er.signup_cutoff > ' . time(); } $sql .= ' AND er.id = ' . $edate->id; $order = 'event_starttime'; $dir = 'ASC'; $o = $db->selectObjectBySql($sql); $o->eventdate = $edate->eventdate; $o->eventstart += $edate->event_starttime; $o->eventend += $edate->event_endtime; $events[] = $o; } $events = expSorter::sort(array('array' => $events, 'sortby' => 'eventstart', 'order' => $sort_asc ? 'ASC' : 'DESC')); return $events; }
/** @define "BASE" "../../../.." */ if (!defined('EXPONENT')) { exit(''); } // Check for form errors $post = $_POST; $post['manual_redirect'] = true; if (!expValidator::check_antispam($post)) { flash('error', gt('Security Validation Failed')); expHistory::back(); } global $db, $user; $f = $db->selectObject("formbuilder_form", "id=" . intval($_POST['id'])); $rpt = $db->selectObject("formbuilder_report", "form_id=" . intval($_POST['id'])); $controls = $db->selectObjects("formbuilder_control", "form_id=" . $f->id . " and is_readonly=0"); $controls = expSorter::sort(array('array' => $controls, 'sortby' => 'rank', 'order' => 'ASC')); $db_data = null; $emailFields = array(); $captions = array(); foreach ($controls as $c) { $ctl = unserialize($c->data); $control_type = get_class($ctl); $def = call_user_func(array($control_type, "getFieldDefinition")); if ($def != null) { $emailValue = htmlspecialchars_decode(call_user_func(array($control_type, 'parseData'), $c->name, $_POST, true)); $value = stripslashes($db->escapeString($emailValue)); //eDebug($value); $varname = $c->name; $db_data->{$varname} = $value; // $fields[$c->name] = call_user_func(array($control_type,'templateFormat'),$value,$ctl); // $emailFields[$c->name] = call_user_func(array($control_type,'templateFormat'),$emailValue,$ctl);
################################################## /** @define "BASE" "../../.." */ if (!defined('EXPONENT')) { exit(''); } $question = null; if (isset($_GET['id'])) { $question = $db->selectObject('poll_question', 'id=' . $_GET['id']); } if ($question) { if ($question->open_results == 1) { $total = 0; $answers = $db->selectObjects('poll_answer', 'question_id=' . $question->id); for ($i = 0; $i < count($answers); $i++) { $total += $answers[$i]->vote_count; } $answers = expSorter::sort(array('array' => $answers, 'sortby' => 'vote_count', 'order' => 'DESC', 'type' => 'a')); $template = new template('simplepollmodule', '_results'); $template->assign('vote_total', $total); $template->assign('question', $question); $template->assign('answers', $answers); $template->output(); } else { echo SITE_403_HTML; } } else { echo SITE_404_HTML; } ?>
// $start = mktime(0,0,0,$info['mon'],$info['mday']+$i,$info['year']); // // $start = $startperiod + ($i*86400); // } else { // range = month // $start = mktime(0,0,0,$info['mon'],$i,$info['year']); // } //$edates = $db->selectObjects("eventdate",$locsql." AND date = '".$start."'"); $edates = $db->selectObjects("eventdate", $locsql . " AND date = {$start}"); $days[$start] = array(); $days[$start] = calendarmodule::_getEventsForDates($edates); for ($j = 0; $j < count($days[$start]); $j++) { $thisloc = expCore::makeLocation($loc->mod, $loc->src, $days[$start][$j]->id); $days[$start][$j]->permissions = array("administrate" => expPermissions::check("administrate", $thisloc) || expPermissions::check("administrate", $loc), "edit" => expPermissions::check("edit", $thisloc) || expPermissions::check("edit", $loc), "delete" => expPermissions::check("delete", $thisloc) || expPermissions::check("delete", $loc)); } $counts[$start] = count($days[$start]); $count += count($days[$start]); $days[$start] = expSorter::sort(array('array' => $days[$start], 'sortby' => 'eventstart', 'order' => 'ASC')); } $template->assign("days", $days); $template->assign("counts", $counts); $template->assign("start", $startperiod); $template->assign("totaldays", $totaldays); // } else if ($viewparams['type'] == "monthly") { // $monthly = array(); // $counts = array(); // $info = getdate($time); // $nowinfo = getdate(time()); // if ($info['mon'] != $nowinfo['mon']) $nowinfo['mday'] = -10; // // Grab non-day numbers only (before end of month) // $week = 0; // $currentweek = -1; // $timefirst = mktime(12,0,0,$info['mon'],1,$info['year']);
function show($view, $loc = null) { global $db; // require_once(BASE."framework/core/subsystems/forms/baseform.php"); // require_once(BASE."framework/core/subsystems/forms/form.php"); if (defined('PREVIEW_READONLY') && !defined('SELECTOR')) { // Pass } else { $f = null; $f = $db->selectObject("formbuilder_form", "location_data='" . serialize($loc) . "'"); if (!$f) { //Create a form if it's missing... $f->name = "New Form"; $f->description = ""; $f->location_data = serialize($loc); $f->table_name = ""; $f->is_email = 0; $f->is_saved = 0; $f->submitbtn = gt('Submit'); $f->resetbtn = gt('Reset'); $f->response = gt('Your form has been submitted'); $f->subject = gt('Submitted form from site'); $frmid = $db->insertObject($f, "formbuilder_form"); //Create Default Report; $rpt->name = gt('Default Report'); $rpt->description = ""; $rpt->location_data = $f->location_data; $rpt->text = ""; $rpt->column_names = ""; $rpt->form_id = $frmid; $db->insertObject($rpt, "formbuilder_report"); $f->id = $frmid; } $floc = unserialize($f->location_data); $controls = $db->selectObjects("formbuilder_control", "form_id=" . $f->id); $controls = expSorter::sort(array('array' => $controls, 'sortby' => 'rank', 'order' => 'ASC')); $form = new form(); $data = expSession::get('formmodule_data_' . $f->id); foreach ($controls as $c) { $ctl = unserialize($c->data); $ctl->_id = $c->id; $ctl->_readonly = $c->is_readonly; if (!empty($data[$c->name])) { $ctl->default = $data[$c->name]; } $form->register($c->name, $c->caption, $ctl); } $form->register("submit", "", new buttongroupcontrol($f->submitbtn, $f->resetbtn, "")); //$form->meta("action","submit_form"); $form->meta("action", "confirm_form"); $form->meta("m", $floc->mod); $form->meta("s", $floc->src); $form->meta("i", $floc->int); $form->meta("id", $f->id); $formmsg = ''; $form->location(expCore::makeLocation("formbuilder", $floc->src, $floc->int)); if (count($controls) == 0) { $form->controls['submit']->disabled = true; $formmsg .= gt('This form is blank. Select "Edit Form" to add input fields.') . '<br>'; } if ($f->is_saved == 0 && $f->is_email == 0) { $form->controls['submit']->disabled = true; $formmsg .= gt('There are no actions assigned to this form. Select "Edit Form Settings" then select "Email Form" and/or "Save to Database".'); } $count = $db->countObjects("formbuilder_" . $f->table_name); $template = new template("formmodule", $view, $loc); $template->assign("moduletitle", $f->name); $template->assign("description", $f->description); if ($formmsg) { flash('notice', $formmsg); } $template->assign("form_html", $form->toHTML($f->id)); $template->assign("form", $f); $template->assign("count", $count); $template->register_permissions(array("administrate", "editform", "editformsettings", "editreport", "viewdata", "editdata", "deletedata"), $loc); $template->output(); } }
# it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../.." */ if (!defined('EXPONENT')) { exit(''); } $item = $db->selectObject('calendar', 'id=' . intval($_GET['id'])); if ($item) { if ($item->is_recurring == 1) { // need to give user options $template = new template('calendarmodule', '_form_delete'); $eventdate = $db->selectObject('eventdate', 'id=' . intval($_GET['date_id'])); $template->assign('checked_date', $eventdate); $eventdates = $db->selectObjects('eventdate', 'event_id=' . $item->id); $eventdates = expSorter::sort(array('array' => $eventdates, 'sortby' => 'date', 'order' => 'ASC')); $template->assign('dates', $eventdates); $template->assign('event', $item); $template->output(); } else { // Process a regular delete include BASE . 'framework/modules-1/calendarmodule/actions/delete.php'; } } else { echo SITE_404_HTML; }
static function form($object) { global $user; $form = new form(); if (!isset($object->id)) { $object->title = ''; $object->body = ''; $object->eventdate = null; $object->eventdate->id = 0; $object->eventdate->date = time(); $object->eventstart = time(); $object->eventend = time() + 3600; $object->is_allday = 0; $object->is_featured = 0; $object->is_recurring = 0; } else { $form->meta('id', $object->id); } $form->register('title', gt('Title'), new textcontrol($object->title)); $form->register('body', gt('Body'), new htmleditorcontrol($object->body)); $form->register(null, '', new htmlcontrol('<hr size="1" />')); if ($object->is_recurring == 1) { $form->register(null, '', new htmlcontrol(gt('Warning: If you change the date below, it will only affect this specific events. All other changes can be applied to this and other events.'), false)); } //$form->register('eventdate',gt('Event Date'),new popupdatetimecontrol($object->eventdate->date,'',false)); $form->register('eventdate', gt('Event Date'), new yuicalendarcontrol($object->eventdate->date, '', false)); $cb = new checkboxcontrol($object->is_allday, false); $cb->jsHooks = array('onclick' => 'exponent_forms_disable_datetime(\'eventstart\',this.form,this.checked); exponent_forms_disable_datetime(\'eventend\',this.form,this.checked);'); $form->register('is_allday', gt('All Day Event'), $cb); $form->register('eventstart', gt('Start Time'), new datetimecontrol($object->eventstart, false)); $form->register('eventend', gt('End Time'), new datetimecontrol($object->eventend, false)); if (!isset($object->id)) { // $customctl = file_get_contents(BASE.'framework/modules-1/calendarmodule/form.part'); $custom = new formtemplate('forms/calendar', '_recurring'); $customctl = $custom->render(); //$datectl = new popupdatetimecontrol($object->eventstart+365*86400,'',false); $datectl = new yuicalendarcontrol($object->eventdate->date + 365 * 86400, '', false); $customctl = str_replace('%%UNTILDATEPICKER%%', $datectl->controlToHTML('untildate'), $customctl); $form->register('recur', gt('Recurrence'), new customcontrol($customctl)); } else { if ($object->is_recurring == 1) { // Edit applies to one or more... $template = new template('calendarmodule', '_recur_dates'); global $db; $eventdates = $db->selectObjects('eventdate', 'event_id=' . $object->id); $eventdates = expSorter::sort(array('array' => $eventdates, 'sortby' => 'date', 'order' => 'ASC')); if (isset($object->eventdate)) { $template->assign('checked_date', $object->eventdate); } $template->assign('dates', $eventdates); $form->register(null, '', new htmlcontrol('<hr size="1"/>' . gt('This event is a recurring event, and occurs on the dates below. Select which dates you wish to apply these edits to.'))); $form->register(null, '', new htmlcontrol('<table cellspacing="0" cellpadding="2" width="100%" class="exp-skin-table">' . $template->render() . '</table>')); $form->meta('date_id', $object->eventdate->id); // Will be 0 if we are creating. } } $form->register('featured_header', '', new htmlcontrol('<h3>' . gt('Featured Event Info') . '</h3><hr size="1" />')); $form->register('is_featured', gt('Feature this event'), new checkboxcontrol($object->is_featured, false)); /* Why was this even here? No views have it. 6/23/09 Time to implement it - Maia*/ // $form->register('image_header','',new htmlcontrol('<h3>'.gt('Upload Image File').'</h3><hr size="1" />')); // $form->register('file',gt('Upload Image'),new uploadcontrol()); // $form->register('tag_header','',new htmlcontrol('<h3>'.gt('Tags').'</h3><hr size="1" />')); $form->register('submit', '', new buttongroupcontrol(gt('Save'), '', gt('Cancel'))); return $form; }
/** * recursively lists the template hierarchy * * @static * @param $parent top level parent id * @param int $depth variable to hold level of recursion * * @return array */ static function getTemplateHierarchyFlat($parent, $depth = 1) { global $db; $arr = array(); $kids = $db->selectObjects('section_template', 'parent=' . $parent); $kids = expSorter::sort(array('array' => $kids, 'sortby' => 'rank', 'order' => 'ASC')); for ($i = 0; $i < count($kids); $i++) { $page = $kids[$i]; $page->depth = $depth; $page->first = $i == 0 ? 1 : 0; $page->last = $i == count($kids) - 1 ? 1 : 0; $arr[] = $page; $arr = array_merge($arr, navigationmodule::getTemplateHierarchyFlat($page->id, $depth + 1)); } return $arr; }
/** * Common Form helper method * * This method, intended to be used solely by other methods of the * section class, creates a base form that all other page types can * build off of. This form includes a name textbox, and either a rank * meta field (hidden input) or a rank dropdown. * * @param $object * * @return \form */ function _commonForm(&$object) { // Create a new blank form. $form = new form(); if (!isset($object->id)) { // This is a new section, so we need to set up some defaults. $object->name = ''; $object->sef_name = ''; $object->active = 1; $object->public = 1; $object->secured = 0; $object->new_window = 0; $object->subtheme = ''; $object->page_title = SITE_TITLE; $object->keywords = SITE_KEYWORDS; $object->description = SITE_DESCRIPTION; if (!isset($object->parent)) { // This is another precaution. The parent attribute // should ALWAYS be set by the caller. //FJD - if that's the case, then we should die. die(SITE_403_REAL_HTML); //$object->parent = 0; } } else { // If we are editing the section, we should store the section's id // in a hidden value, so that it comes through when the form is // submitted. $form->meta('id', $object->id); } // The name of the section, as it will be linked in the section hierarchy. $form->register('name', gt('Name'), new textcontrol($object->name)); $form->register('sef_name', gt('SEF Name') . '<p class="sefinfo">' . gt('If you don\'t put in an SEF Name one will be generated based on the title provided. SEF names can only contain alpha-numeric characters, hyphens and underscores.') . '</p>', new textcontrol($object->sef_name)); if (!isset($object->id)) { // This is a new section, so we can add the positional dropdown // Pull the database object in from the global scope. global $db; // Retrieve all of the sections that are siblings of the new section $sections = $db->selectObjects('section', 'parent=' . $object->parent); if (count($sections) && $object->parent >= 0) { // Initialize the sorting subsystem so that we can order the sections // by rank, ascending, and get the proper ordering. $sections = expSorter::sort(array('array' => $sections, 'sortby' => 'rank', 'order' => 'ASC')); // Generate the Position dropdown array. $positions = array(gt('At the Top')); foreach ($sections as $section) { $positions[] = sprintf(gt('After') . " %s", $section->name); } $form->meta('rank', count($positions) - 1); //$form->register('rank',gt('Rank'),new dropdowncontrol(count($positions)-1,$positions)); } else { // If there are no siblings, the new section gets the first // slot, with a rank of 0. $form->meta('rank', 0); } // Store the section's parent in a hidden field, so that it comes through // when the form is submitted. $form->meta('parent', $object->parent); } else { if ($object->parent >= 0) { // Allow them to change parents, but not if the section is outside of the hierarchy (parent > 0) $form->register('parent', gt('Parent Page'), new dropdowncontrol($object->parent, navigationmodule::levelDropdownControlArray(0, 0, array($object->id), true, 'manage'))); } } $form->register('new_window', gt('Open in New Window'), new checkboxcontrol($object->new_window, false)); // Return the form to the calling scope, which should always be a // member method of this class. return $form; }
public static function listActiveControllers() { global $db; $controllers = expModules::listUserRunnableControllers(); foreach ($controllers as $module) { if (class_exists($module)) { $mod = new $module(); $modstate = $db->selectObject("modstate", "module='{$module}'"); $moduleInfo[$module] = null; $moduleInfo[$module]->class = $module; $moduleInfo[$module]->name = $mod->name(); $moduleInfo[$module]->author = $mod->author(); $moduleInfo[$module]->description = $mod->description(); $moduleInfo[$module]->codequality = isset($mod->codequality) ? $mod->codequality : 'alpha'; $moduleInfo[$module]->active = $modstate != null ? $modstate->active : 0; } } $moduleInfo = expSorter::sort(array('array' => $moduleInfo, 'sortby' => 'name', 'order' => 'ASC', 'ignore_case' => true)); return $moduleInfo; }
public function showall_by_tags() { global $db; // set history expHistory::set('viewable', $this->params); // get the tag being passed $tag = new expTag($this->params['tag']); // find all the id's of the blog posts for this blog module $port_ids = $db->selectColumn('portfolio', 'id', $this->aggregateWhereClause()); // find all the blogs that this tag is attached to $ports = $tag->findWhereAttachedTo('portfolio'); // loop the blogs for this tag and find out which ones belong to this module $ports_by_tags = array(); foreach ($ports as $port) { if (in_array($port->id, $port_ids)) { $ports_by_tags[] = $port; } } // create a pagination object for the blog posts and render the action $order = 'created_at'; $limit = empty($this->config['limit']) ? 10 : $this->config['limit']; $page = new expPaginator(array('records' => $ports_by_tags, 'limit' => $limit, 'order' => $order, 'controller' => $this->baseclassname, 'action' => $this->params['action'], 'columns' => array('Title' => 'title'))); $page->records = expSorter::sort(array('array' => $page->records, 'sortby' => 'rank', 'order' => 'ASC', 'ignore_case' => true)); assign_to_template(array('page' => $page)); }
public function getRates($items) { global $order; // Require the main ups class and upsRate include_once BASE . 'external/ups-php/classes/class.ups.php'; include_once BASE . 'external/ups-php/classes/class.upsRate.php'; $upsConnect = new ups($this->configdata['accessnumber'], $this->configdata['username'], $this->configdata['password']); $upsConnect->setTemplatePath(BASE . 'external/ups-php/xml/'); $upsConnect->setTestingMode($this->configdata['testmode']); // Change this to 0 for production $upsRate = new upsRate($upsConnect); $upsRate->request(array('Shop' => true)); // set the address we will be shipping from. this should be in the config data $upsRate->shipper($this->configdata['shipfrom']); // get the current shippingmethod and format the address for ups $currentmethod = $order->getCurrentShippingMethod(); $upsRate->shipTo($this->formatAddress($currentmethod)); // set the standard box sizes. $box_width = empty($this->configdata['default_width']) ? 0 : $this->configdata['default_width']; $box_height = empty($this->configdata['default_height']) ? 0 : $this->configdata['default_height']; $box_length = empty($this->configdata['default_length']) ? 0 : $this->configdata['default_length']; $box_volume = $box_height * $box_width * $box_length; // set some starting/default values $weight = 0; $volume = 0; $count = 0; $package_items = array(); // loop each product in this shipment and create the packages $has_giftcard = false; foreach ($items->orderitem as $item) { for ($i = 0; $i < $item->quantity; $i++) { if (empty($item->product->no_shipping) && $item->product->requiresShipping == true) { if ($item->product_type != 'giftcard') { $lbs = empty($item->product->weight) ? $this->configdata['default_max_weight'] : $item->product->weight; $width = empty($item->product->width) ? $this->configdata['default_width'] : $item->product->width; $height = empty($item->product->height) ? $this->configdata['default_height'] : $item->product->height; $length = empty($item->product->length) ? $this->configdata['default_length'] : $item->product->length; $package_items[$count]->volume = $width * $length * $height; $package_items[$count]->weight = $lbs; $package_items[$count]->w = $width; $package_items[$count]->h = $height; $package_items[$count]->l = $length; $package_items[$count]->name = $item->product->title; $count += 1; } else { $has_giftcard = true; } } } } // kludge for the giftcard shipping if (count($package_items) == 0 && $has_giftcard) { $rates = array("03" => array("id" => "03", "title" => "UPS Ground", "cost" => 5.0), "02" => array("id" => "02", "title" => "UPS Second Day Air", "cost" => 10.0), "01" => array("id" => "01", "title" => "UPS Next Day Air", "cost" => 20.0)); return $rates; } // sort the items by volume $package_items = expSorter::sort(array('array' => $package_items, 'sortby' => 'volume', 'order' => 'DESC')); // loop over all the items and try to put them into packages in a semi-intelligent manner // we have sorted the list of items from biggest to smallest. Items with a volume larger than // our standard box will generate a package with the dimensions set to the size of the item. // otherwise we just keep stuffing items in the current package until we can't find anymore that will // fit. Once that happens we close that package and start a new one...repeating until we are out of items $space_left = $box_volume; $total_weight = 0; while (!empty($package_items)) { $no_more_room = true; $used = array(); foreach ($package_items as $idx => $pi) { if ($pi->volume > $box_volume) { # echo $pi->name."is too big for standard box <br>"; # eDebug('created OVERSIZED package with weight of '.$pi->weight); # eDebug('dimensions: height: '.$pi->h." width: ".$pi->w." length: ".$pi->l); # echo "<hr>"; $weight = $pi->weight > 1 ? $pi->weight : 1; $upsRate->package(array('description' => 'shipment', 'weight' => $weight, 'code' => '02', 'length' => $pi->l, 'width' => $pi->w, 'height' => $pi->h)); $used[] = $idx; $no_more_room = false; } elseif ($pi->volume <= $space_left) { $space_left = $space_left - $pi->volume; $total_weight += $pi->weight; # echo "Adding ".$pi->name."<br>"; # echo "Space left in current box: ".$space_left."<br>"; $no_more_room = false; $used[] = $idx; } } // remove the used items from the array so they wont be there on the next go around. foreach ($used as $idx) { unset($package_items[$idx]); } // if there is no more room left on the current package or we are out of items then // add the package to the shippment. if ($no_more_room || empty($package_items) && $total_weight > 0) { $total_weight = $total_weight > 1 ? $total_weight : 1; # eDebug('created standard sized package with weight of '.$total_weight); # echo "<hr>"; $upsRate->package(array('description' => 'shipment', 'weight' => $total_weight, 'code' => '02', 'length' => $box_length, 'width' => $box_width, 'height' => $box_height)); $space_left = $box_volume; $total_weight = 0; } } $upsRate->shipment(array('description' => 'my description', 'serviceType' => '03')); $rateFromUPS = $upsRate->sendRateRequest(); $handling = empty($has_giftcard) ? 0 : 5; if ($rateFromUPS['RatingServiceSelectionResponse']['Response']['ResponseStatusCode']['VALUE'] == 1) { $rates = array(); $available_methods = $this->availableMethods(); foreach ($rateFromUPS['RatingServiceSelectionResponse']['RatedShipment'] as $rate) { if (array_key_exists($rate['Service']['Code']['VALUE'], $available_methods)) { $rates[$rate['Service']['Code']['VALUE']] = $rate['TotalCharges']['MonetaryValue']['VALUE']; $rates[$rate['Service']['Code']['VALUE']] = array('id' => $rate['Service']['Code']['VALUE'], 'title' => $this->shippingmethods[$rate['Service']['Code']['VALUE']], 'cost' => $rate['TotalCharges']['MonetaryValue']['VALUE'] + $handling); } } return $rates; } else { return $rateFromUPS['RatingServiceSelectionResponse']['Response']['Error']['ErrorDescription']['VALUE']; } }
static function _getEventsForDates($edates, $sort_asc = true, $featuredonly = false) { global $db; $events = array(); $featuresql = ""; if ($featuredonly) { $featuresql = " AND is_featured=1"; } foreach ($edates as $edate) { $o = $db->selectObject("calendar", "id=" . $edate->event_id . $featuresql); if ($o != null) { $o->eventdate = $edate; $o->eventstart += $edate->date; $o->eventend += $edate->date; $events[] = $o; } } $events = expSorter::sort(array('array' => $events, 'sortby' => 'eventstart', 'order' => $sort_asc ? 'ASC' : 'DESC')); return $events; }