function publications_admin_create() { if (!xarVarFetch('ptid', 'id', $data['ptid'])) { return; } if (!xarVarFetch('new_cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('save', 'str', $save, NULL, XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code // This has been disabled for now // if (!xarSecConfirmAuthKey()) return; $data['items'] = array(); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $isvalid = $data['object']->checkInput(); $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); if ($data['preview'] || !$isvalid) { // Show debug info if called for if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) { var_dump($data['object']->getInvalids()); } // Preview or bad data: redisplay the form $data['properties'] = $data['object']->getProperties(); if ($data['preview']) { $data['tab'] = 'preview'; } return xarTplModule('publications', 'admin', 'new', $data); } // Create the object $id = $data['object']->createItem(); // if we can edit publications, go to admin view, otherwise go to user view if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) { // Redirect if we came from somewhere else $cuurent_listview = xarSession::getVar('publications_current_listview'); if (!empty($cuurent_listview)) { xarController::redirect($cuurent_listview); } xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid']))); } else { xarController::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid']))); } return true; }
/** * Get customer info */ function shop_userapi_customerinfo($args) { $values = array(); if (xarUserIsLoggedIn()) { $id = xarUserGetVar('id'); } extract($args); if (isset($id)) { sys::import('modules.dynamicdata.class.objects.master'); $custobject = DataObjectMaster::getObject(array('name' => 'shop_customers')); $some_id = $custobject->getItem(array('itemid' => $id)); if (!$some_id) { //This user must have a role but no customer account. This probably happened because a web admin uninstalled the shop module, deleting all the customer accounts but not deleting the associated roles. Let's re-create the customer record with just the id so we don't get snagged later $id = $custobject->createItem(array('id' => $id)); $custobject->getItem(array('itemid' => $id)); } $values = $custobject->getFieldValues(); return $values; } else { return; } }
/** * import pictures into publications */ function publications_admin_importpictures() { if (!xarSecurityCheck('AdminPublications')) { return; } // Get parameters if (!xarVarFetch('basedir', 'isset', $basedir, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('baseurl', 'isset', $baseurl, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('thumbnail', 'isset', $thumbnail, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filelist', 'isset', $filelist, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('refresh', 'isset', $refresh, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('title', 'isset', $title, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('summary', 'isset', $summary, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('content', 'isset', $content, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('usefilemtime', 'isset', $usefilemtime, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('test', 'isset', $test, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) { return; } // Initialise the template variables $data = array(); if (!isset($baseurl)) { $data['baseurl'] = sys::code() . 'modules/publications/xarimages/'; } else { $data['baseurl'] = $baseurl; } if (!isset($basedir)) { $data['basedir'] = realpath($data['baseurl']); } else { $data['basedir'] = realpath($basedir); } if (!isset($thumbnail)) { $data['thumbnail'] = 'tn_'; } else { $data['thumbnail'] = $thumbnail; } $data['filelist'] = xarModAPIFunc('publications', 'admin', 'browse', array('basedir' => $data['basedir'], 'filetype' => '(gif|jpg|jpeg|png)')); // try to match the thumbnails with the pictures $data['thumblist'] = array(); if (!empty($data['thumbnail'])) { foreach ($data['filelist'] as $file) { // for subdir/myfile.jpg $fileparts = pathinfo($file); // jpg $extension = $fileparts['extension']; // subdir $dirname = $fileparts['dirname']; // myfile $basename = $fileparts['basename']; $basename = preg_replace("/\\.{$extension}/", '', $basename); if (!empty($dirname) && $dirname != '.') { $thumb = $dirname . '/' . $data['thumbnail'] . $basename; } else { $thumb = $data['thumbnail'] . $basename; } // subdir/tn_file.jpg if (in_array($thumb . '.' . $extension, $data['filelist'])) { $data['thumblist'][$file] = $thumb . '.' . $extension; // subdir/tn_file_jpg.jpg } elseif (in_array($thumb . '_' . $extension . '.' . $extension, $data['filelist'])) { $data['thumblist'][$file] = $thumb . '_' . $extension . '.' . $extension; // subdir/tn_file.jpg.jpg } elseif (in_array($thumb . '.' . $extension . '.' . $extension, $data['filelist'])) { $data['thumblist'][$file] = $thumb . '.' . $extension . '.' . $extension; } } if (count($data['thumblist']) > 0) { $deletelist = array_values($data['thumblist']); $data['filelist'] = array_diff($data['filelist'], $deletelist); } } if (isset($refresh) || isset($test) || isset($import)) { // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } } $data['authid'] = xarSecGenAuthKey(); // Get current publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // Set default pubtype to Pictures (if it exists) if (!isset($ptid) && isset($pubtypes[5])) { $ptid = 5; $title = 'title'; $summary = 'summary'; $content = 'body'; } $data['pubtypes'] = $pubtypes; $data['fields'] = array(); $data['cats'] = array(); if (!empty($ptid)) { $data['ptid'] = $ptid; $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields'); $pubfieldtypes = xarModAPIFunc('publications', 'user', 'getpubfieldtypes'); $pubfieldformats = xarModAPIFunc('publications', 'user', 'getpubfieldformats'); foreach ($pubfields as $field => $dummy) { if (($pubfieldtypes[$field] == 'text' || $pubfieldtypes[$field] == 'string') && !empty($pubtypes[$ptid]['config'][$field]['label']) && $pubtypes[$ptid]['config'][$field]['format'] != 'fileupload') { $data['fields'][$field] = $pubtypes[$ptid]['config'][$field]['label'] . ' [' . $pubfieldformats[$pubtypes[$ptid]['config'][$field]['format']] . ']'; } } $catlist = array(); $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); foreach ($rootcats as $catid) { $catlist[$catid['category_id']] = 1; } $seencid = array(); if (isset($cids) && is_array($cids)) { foreach ($cids as $catid) { if (!empty($catid)) { $seencid[$catid] = 1; } } } $cids = array_keys($seencid); foreach (array_keys($catlist) as $catid) { $data['cats'][] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $catid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1)); } } $data['selected'] = array(); if (!isset($refresh) && isset($filelist) && is_array($filelist) && count($filelist) > 0) { foreach ($filelist as $file) { if (!empty($file) && in_array($file, $data['filelist'])) { $data['selected'][$file] = 1; } } } if (isset($title) && isset($data['fields'][$title])) { $data['title'] = $title; } if (isset($summary) && isset($data['fields'][$summary])) { $data['summary'] = $summary; } if (isset($content) && isset($data['fields'][$content])) { $data['content'] = $content; } if (empty($usefilemtime)) { $data['usefilemtime'] = 0; } else { $data['usefilemtime'] = 1; } if (isset($data['ptid']) && isset($data['content']) && count($data['selected']) > 0 && (isset($test) || isset($import))) { // TODO: allow changing the order of import + editing the titles etc. before creating the publications $data['logfile'] = ''; foreach (array_keys($data['selected']) as $file) { $curfile = realpath($basedir . '/' . $file); if (!file_exists($curfile) || !is_file($curfile)) { continue; } $filename = $file; if (empty($baseurl)) { $imageurl = $file; } elseif (substr($baseurl, -1) == '/') { $imageurl = $baseurl . $file; } else { $imageurl = $baseurl . '/' . $file; } if (!empty($data['thumblist'][$file])) { if (empty($baseurl)) { $thumburl = $data['thumblist'][$file]; } elseif (substr($baseurl, -1) == '/') { $thumburl = $baseurl . $data['thumblist'][$file]; } else { $thumburl = $baseurl . '/' . $data['thumblist'][$file]; } } else { $thumburl = ''; } $article = array('title' => ' ', 'summary' => '', 'body' => '', 'notes' => '', 'pubdate' => empty($usefilemtime) ? time() : filemtime($curfile), 'state' => 2, 'ptid' => $data['ptid'], 'cids' => $cids, 'pubtype_id' => $data['ptid'], 'owner' => xarUserGetVar('id'), 'id' => 0); if (!empty($data['title']) && !empty($filename)) { $article[$data['title']] = $filename; } if (!empty($data['summary']) && !empty($thumburl)) { $article[$data['summary']] = $thumburl; } if (!empty($data['content']) && !empty($imageurl)) { $article[$data['content']] = $imageurl; } if (isset($test)) { // preview the first file as a test $data['preview'] = xarModFunc('publications', 'user', 'display', array('article' => $article, 'preview' => true)); break; } else { $id = xarModAPIFunc('publications', 'admin', 'create', $article); if (empty($id)) { return; // throw back } else { $data['logfile'] .= xarML('File #(1) was imported as #(2) #(3)', $curfile, $pubtypes[$data['ptid']]['description'], $id); $data['logfile'] .= '<br />'; } } } } // Return the template variables defined in this function return $data; }
/** * Select existing payment method or create new one to use for this transaction */ function shop_user_paymentmethod() { // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be $shippingaddress = xarSession::getVar('shippingaddress'); if (empty($shippingaddress)) { xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress')); return true; } $shop = xarSession::getVar('shop'); if (!xarUserIsLoggedIn() || empty($shop)) { xarResponse::redirect(xarModURL('shop', 'user', 'main')); return true; } if (!xarVarFetch('proceedsaved', 'str', $proceedsaved, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('proceednew', 'str', $proceednew, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('paymentmethod', 'str', $paymentmethod, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('remove', 'str', $remove, NULL, XARVAR_NOT_REQUIRED)) { return; } $cust = xarMod::APIFunc('shop', 'user', 'customerinfo'); $data['cust'] = $cust; sys::import('modules.dynamicdata.class.objects.master'); sys::import('modules.dynamicdata.class.properties.master'); $shippingobject = DataObjectMaster::getObject(array('name' => 'shop_shippingaddresses')); $shippingobject->getItem(array('itemid' => xarSession::getVar('shippingaddress'))); $shippingvals = $shippingobject->getFieldValues(); $data['shippingvals'] = $shippingvals; // Get the saved payment methods, if any exist $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_paymentmethods')); $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'where' => 'customer eq ' . xarUserGetVar('id')); $paymentmethods = $mylist->getItems($filters); $data['paymentmethods'] = $paymentmethods; $data['paymentobject'] = DataObjectMaster::getObject(array('name' => 'shop_paymentmethods')); $data['paymentobject']->properties['name']->display_show_salutation = false; $data['paymentobject']->properties['name']->display_show_middlename = false; $data['paymentobject']->properties['address']->display_rows = 1; $data['paymentobject']->properties['address']->display_show_country = false; $data['properties'] = $data['paymentobject']->getProperties(); if ($remove) { if ($remove == xarSession::getVar('paymentmethod')) { xarSession::delVar('paymentmethod'); } $data['paymentobject']->getItem(array('itemid' => $remove)); $data['paymentobject']->deleteItem(); xarResponse::redirect(xarModURL('shop', 'user', 'paymentmethod')); return true; } $selectedpaymentmethod = xarSession::getVar('paymentmethod'); if (!empty($selectedpaymentmethod)) { $data['paymentmethod'] = $selectedpaymentmethod; } // If we're using a saved payment method... if ($proceedsaved) { xarSession::setVar('paymentmethod', $paymentmethod); xarResponse::redirect(xarModURL('shop', 'user', 'order')); return true; } elseif ($proceednew) { // We're not using a saved payment method... $isvalid = $data['paymentobject']->checkInput(); if (isset($exp_date)) { $exp_month = substr($exp_date, 0, 2); $exp_year = substr($exp_date, 2, 4); $reverse_date = $exp_year . $exp_month; $minimum_date = date('ym', time()); if ($minimum_date > $reverse_date) { $errors['exp_date'] = true; } } if (isset($errors)) { xarSession::setVar('errors', $errors); } if (!$isvalid) { return xarTplModule('shop', 'user', 'paymentmethod', $data); } else { xarSession::setVar('paymentmethod', $data['paymentobject']->createItem()); xarResponse::redirect(xarModURL('shop', 'user', 'order')); return true; } } return $data; }
/** * manage publication types (all-in-one function for now) */ function publications_admin_importpages() { if (!xarSecurityCheck('AdminPublications')) { return; } // Get parameters if (!xarVarFetch('basedir', 'isset', $basedir, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filelist', 'isset', $filelist, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('refresh', 'isset', $refresh, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('content', 'isset', $content, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('title', 'isset', $title, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filterhead', 'isset', $filterhead, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filtertail', 'isset', $filtertail, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('findtitle', 'isset', $findtitle, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('numrules', 'isset', $numrules, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('search', 'isset', $search, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('replace', 'isset', $replace, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('test', 'isset', $test, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) { return; } // Initialise the template variables $data = array(); if (empty($basedir)) { $data['basedir'] = realpath(sys::code() . 'modules/publications'); } else { $data['basedir'] = realpath($basedir); } $data['filelist'] = xarModAPIFunc('publications', 'admin', 'browse', array('basedir' => $data['basedir'], 'filetype' => 'html?')); if (isset($refresh) || isset($test) || isset($import)) { // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } } $data['authid'] = xarSecGenAuthKey(); // Get current publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); $data['pubtypes'] = $pubtypes; $data['fields'] = array(); $data['cats'] = array(); if (!empty($ptid)) { $data['ptid'] = $ptid; $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields'); $pubfieldtypes = xarModAPIFunc('publications', 'user', 'getpubfieldtypes'); $pubfieldformats = xarModAPIFunc('publications', 'user', 'getpubfieldformats'); foreach ($pubfields as $field => $dummy) { if (($pubfieldtypes[$field] == 'text' || $pubfieldtypes[$field] == 'string') && !empty($pubtypes[$ptid]['config'][$field]['label']) && $pubtypes[$ptid]['config'][$field]['format'] != 'fileupload') { $data['fields'][$field] = $pubtypes[$ptid]['config'][$field]['label'] . ' [' . $pubfieldformats[$pubtypes[$ptid]['config'][$field]['format']] . ']'; } } $catlist = array(); $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); foreach ($rootcats as $catid) { $catlist[$catid['category_id']] = 1; } $seencid = array(); if (isset($cids) && is_array($cids)) { foreach ($cids as $catid) { if (!empty($catid)) { $seencid[$catid] = 1; } } } $cids = array_keys($seencid); foreach (array_keys($catlist) as $catid) { $data['cats'][] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $catid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1)); } } $data['selected'] = array(); if (!isset($refresh) && isset($filelist) && is_array($filelist) && count($filelist) > 0) { foreach ($filelist as $file) { if (!empty($file) && in_array($file, $data['filelist'])) { $data['selected'][$file] = 1; } } } if (isset($title) && isset($data['fields'][$title])) { $data['title'] = $title; } if (isset($content) && isset($data['fields'][$content])) { $data['content'] = $content; } if (!isset($filterhead)) { $data['filterhead'] = '#^.*<body[^>]*>#is'; } else { $data['filterhead'] = $filterhead; } if (!isset($filtertail)) { $data['filtertail'] = '#</body.*$#is'; } else { $data['filtertail'] = $filtertail; } if (!isset($findtitle)) { $data['findtitle'] = '#<title>(.*?)</title>#is'; } else { $data['findtitle'] = $findtitle; } if (!isset($numrules)) { $numrules = 3; } $data['search'] = array(); $data['replace'] = array(); for ($i = 0; $i < $numrules; $i++) { if (isset($search[$i])) { $data['search'][$i] = $search[$i]; if (isset($replace[$i])) { $data['replace'][$i] = $replace[$i]; } else { $data['replace'][$i] = ''; } } else { $data['search'][$i] = ''; $data['replace'][$i] = ''; } } if (isset($data['ptid']) && isset($data['content']) && count($data['selected']) > 0 && (isset($test) || isset($import))) { $mysearch = array(); $myreplace = array(); for ($i = 0; $i < $numrules; $i++) { if (!empty($data['search'][$i])) { $mysearch[] = $data['search'][$i]; if (!empty($data['replace'][$i])) { $myreplace[] = $data['replace'][$i]; } else { $myreplace[] = ''; } } } $data['logfile'] = ''; foreach (array_keys($data['selected']) as $file) { $curfile = realpath($basedir . '/' . $file); if (!file_exists($curfile) || !is_file($curfile)) { continue; } $page = @join('', file($curfile)); if (!empty($data['findtitle']) && preg_match($data['findtitle'], $page, $matches)) { $title = $matches[1]; } else { $title = ''; } if (!empty($data['filterhead'])) { $page = preg_replace($filterhead, '', $page); } if (!empty($data['filtertail'])) { $page = preg_replace($filtertail, '', $page); } if (count($mysearch) > 0) { $page = preg_replace($mysearch, $myreplace, $page); } $article = array('title' => ' ', 'summary' => '', 'body' => '', 'notes' => '', 'pubdate' => filemtime($curfile), 'state' => 2, 'ptid' => $data['ptid'], 'cids' => $cids, 'pubtype_id' => $data['ptid'], 'owner' => xarUserGetVar('id'), 'id' => 0); if (!empty($data['title']) && !empty($title)) { $article[$data['title']] = $title; } $article[$data['content']] = $page; if (isset($test)) { // preview the first file as a test $data['preview'] = xarModFunc('publications', 'user', 'display', array('article' => $article, 'preview' => true)); break; } else { $id = xarModAPIFunc('publications', 'admin', 'create', $article); if (empty($id)) { return; // throw back } else { $data['logfile'] .= xarML('File #(1) was imported as #(2) #(3)', $curfile, $pubtypes[$data['ptid']]['description'], $id); $data['logfile'] .= '<br />'; } } } } $data['filterhead'] = xarVarPrepForDisplay($data['filterhead']); $data['filtertail'] = xarVarPrepForDisplay($data['filtertail']); $data['findtitle'] = xarVarPrepForDisplay($data['findtitle']); for ($i = 0; $i < $numrules; $i++) { if (!empty($data['search'][$i])) { $data['search'][$i] = xarVarPrepForDisplay($data['search'][$i]); } if (!empty($data['replace'][$i])) { $data['replace'][$i] = xarVarPrepForDisplay($data['replace'][$i]); } } // Return the template variables defined in this function return $data; }
/** * Publications Module * * @package modules * @subpackage publications module * @category Third Party Xaraya Module * @version 2.0.0 * @copyright (C) 2011 Netspan AG * @license GPL {@link http://www.gnu.org/licenses/gpl.html} * @author Marc Lutolf <*****@*****.**> */ function publications_userapi_gettranslationid($args) { if (!isset($args['id'])) { throw new BadParameterException('id'); } if (empty($args['id'])) { return 0; } // We can check on a full locale or just a partial one (excluding charset) if (empty($args['partiallocale'])) { $args['partiallocale'] = 0; } // We can look for a specific translation if (empty($args['locale'])) { $locale = xarUserGetNavigationLocale(); } else { $locale = $args['locale']; } sys::import('xaraya.structures.query'); if ($args['partiallocale']) { $parts = explode('.', $locale); $locale = $parts[0]; } $xartable = xarDB::getTables(); if (empty($args['locale'])) { // Return the id of the translation if it exists, or else the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('id'); $q->eq('locale', $locale); $c[] = $q->peq('id', $args['id']); $c[] = $q->peq('parent_id', $args['id']); $q->qor($c); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } elseif ($args['locale'] == xarUserGetNavigationLocale()) { // No need to look further return $args['id']; } elseif ($args['locale'] == xarModVars::get('publications', 'defaultlanguage')) { // Force getting the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('parent_id'); $q->eq('id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } // If this was already the base document, return its ID if (empty($result['parent_id'])) { return $args['id']; } // Else return the parent ID return $result['parent_id']; } else { // Force getting another translation $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.parent_id', 'p1.parent_id'); $q->addfield('p2.id'); $q->eq('p2.locale', $locale); $q->eq('p1.id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } if (xarUserGetVar('uname') == 'random') { $xartable = xarDB::getTables(); $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.id', 'p1.parent_id'); $q->addfield('p1.id'); $c[] = $q->peq('p1.id', $args['id']); $c[] = $q->peq('p1.parent_id', $args['id']); $c[] = $q->peq('p2.id', $args['id']); $q->qor($c); $d[] = $q->peq('p1.locale', $args['locale']); $d[] = $q->peq('p2.locale', $args['locale']); $q->qor($d); if (!$q->run()) { return $args['id']; } $q->qecho(); $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } }
function publications_user_view($args) { // Get parameters if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('andcids', 'str', $andcids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) { return; } // TODO: put the query string through a proper parser, so searches on multiple words can be done. if (!xarVarFetch('q', 'pre:trim:passthru:str:1:200', $q, NULL, XARVAR_NOT_REQUIRED)) { return; } // can't use list enum here, because we don't know which sorts might be used // True - but we can provide some form of validation and normalisation. // The original 'regexp:/^[\w,]*$/' lets through *any* non-space character. // This validation will accept a list of comma-separated words, and will lower-case, trim // and strip out non-alphanumeric characters from each word. if (!xarVarFetch('sort', 'strlist:,:pre:trim:lower:alnum', $sort, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('numcols', 'int:0', $numcols, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('owner', 'id', $owner, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('pubdate', 'str:1', $pubdate, NULL, XARVAR_NOT_REQUIRED)) { return; } // This may not be set via user input, only e.g. via template tags, API calls, blocks etc. // if(!xarVarFetch('startdate','int:0', $startdate, NULL, XARVAR_NOT_REQUIRED)) {return;} // if(!xarVarFetch('enddate', 'int:0', $enddate, NULL, XARVAR_NOT_REQUIRED)) {return;} // if(!xarVarFetch('where', 'str', $where, NULL, XARVAR_NOT_REQUIRED)) {return;} // Added to impliment an Alpha Pager if (!xarVarFetch('letter', 'pre:lower:passthru:str:1:20', $letter, NULL, XARVAR_NOT_REQUIRED)) { return; } // Override if needed from argument array (e.g. ptid, numitems etc.) extract($args); $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // We need a valid pubtype number here if (!is_numeric($ptid) || !isset($pubtypes[$ptid])) { return xarResponse::NotFound(); } // Constants used throughout. // // publications module ID $c_modid = xarMod::getID('publications'); // state: front page or approved $c_posted = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); // Default parameters if (!isset($startnum)) { $startnum = 1; } // Check if we want the default 'front page' if (!isset($catid) && !isset($cids) && empty($ptid) && !isset($owner)) { $ishome = true; // default publication type $ptid = xarModVars::get('publications', 'defaultpubtype'); // frontpage state $state = array(PUBLICATIONS_STATE_FRONTPAGE); } else { $ishome = false; // frontpage or approved state $state = $c_posted; } // Get the publication type for this display $data['pubtypeobject'] = DataObjectMaster::getObject(array('name' => 'publications_types')); $data['pubtypeobject']->getItem(array('itemid' => $ptid)); // Get the settings of this publication type $data['settings'] = xarMod::apiFunc('publications', 'user', 'getsettings', array('ptid' => $ptid)); // Get the template for this publication type if ($ishome) { $data['template'] = 'frontpage'; } else { $data['template'] = $data['pubtypeobject']->properties['template']->getValue(); } $isdefault = 0; // check default view for this type of publications if (empty($catid) && empty($cids) && empty($owner) && empty($sort)) { if (substr($data['settings']['defaultview'], 0, 1) == 'c') { $catid = substr($data['settings']['defaultview'], 1); } } // Do not transform titles if we are not transforming output at all. if (empty($data['settings']['do_transform'])) { $data['settings']['dotitletransform'] = 0; } // Page template for frontpage or depending on publication type (optional) // Note : this cannot be overridden in templates if (!empty($data['settings']['page_template'])) { xarTplSetPageTemplateName($data['settings']['page_template']); } if (empty($data['settings']['defaultsort'])) { $defaultsort = 'date'; } else { $defaultsort = $data['settings']['defaultsort']; } if (empty($sort)) { $sort = $defaultsort; } // TODO: show this *after* category list when we start from categories :) // Navigation links $data['publabel'] = xarML('Publication'); $data['publinks'] = xarModAPIFunc('publications', 'user', 'getpublinks', array('ptid' => $ishome ? '' : $ptid, 'state' => $c_posted, 'count' => $data['settings']['show_pubcount'])); $data['pager'] = ''; // Add Sort to data passed to template so that we can automatically turn on alpha pager, if needed $data['sort'] = $sort; // Add current display letter, so that we can highlight the current filter in the alpha pager $data['letter'] = $letter; // Get the users requested number of stories per page. // If user doesn't care, use the site default if (xarUserIsLoggedIn()) { // TODO: figure how to let users specify their settings // COMMENT: if the settings were split into separate module variables, // then they could all be individually over-ridden by each user. //$numitems = xarModUserGetVar('items_per_page'); } if (empty($numitems)) { if (!empty($settings['items_per_page'])) { $numitems = $settings['items_per_page']; } else { $numitems = 20; } } // turn $catid into $cids array and set $andcids flag if (!empty($catid)) { if (strpos($catid, ' ')) { $cids = explode(' ', $catid); $andcids = true; } elseif (strpos($catid, '+')) { $cids = explode('+', $catid); $andcids = true; } elseif (strpos($catid, '-')) { $cids = explode('-', $catid); $andcids = false; } else { $cids = array($catid); if (strstr($catid, '_')) { $andcids = false; // don't combine with current category } else { $andcids = true; } } } else { if (empty($cids)) { $cids = array(); } if (!isset($andcids)) { $andcids = true; } } // rebuild $catid in standard format again $catid = null; if (count($cids) > 0) { $seencid = array(); foreach ($cids as $cid) { // make sure cids are numeric if (!empty($cid) && preg_match('/^_?[0-9]+$/', $cid)) { $seencid[$cid] = 1; } } $cids = array_keys($seencid); sort($cids, SORT_NUMERIC); if ($andcids) { $catid = join('+', $cids); } else { $catid = join('-', $cids); } } // every field you always wanted to know about but were afraid to ask for :) $extra = array(); // $extra[] = 'author'; // Note: we always include cids for security checks now (= performance impact if show_categories was 0) $extra[] = 'cids'; if ($data['settings']['show_hitcount']) { $extra[] = 'counter'; } if ($data['settings']['show_ratings']) { $extra[] = 'rating'; } $now = time(); if (empty($startdate) || !is_numeric($startdate) || $startdate > $now) { $startdate = null; } if (empty($enddate) || !is_numeric($enddate) || $enddate > $now) { $enddate = $now; } if (empty($pubdate) || !preg_match('/^\\d{4}(-\\d+(-\\d+|)|)$/', $pubdate)) { $pubdate = null; } if (empty($where)) { $where = null; } // Modify the where clause if an Alpha filter has been specified. if (!empty($letter)) { // We will allow up to three initial letters, anything more than that is assumed to be 'Other'. // Need to also be very wary of SQL injection, since we are not using bind variables here. // TODO: take into account international characters. if (preg_match('/^[a-z]{1,3}$/i', $letter)) { $extrawhere = "title LIKE '{$letter}%'"; } else { // Loop through the alphabet for the 'not in' part. $letterwhere = array(); for ($i = ord('a'); $i <= ord('z'); $i++) { $letterwhere[] = "title NOT LIKE '" . chr($i) . "%'"; } $extrawhere = implode(' and ', $letterwhere); } if ($where == null) { $where = $extrawhere; } else { $where .= $extrawhere; } } // Get publications $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => isset($ptid) ? $ptid : null, 'owner' => $owner, 'state' => $state, 'sort' => $sort, 'extra' => $extra, 'where' => $where, 'search' => $q, 'numitems' => $numitems, 'pubdate' => $pubdate, 'startdate' => $startdate, 'enddate' => $enddate)); if (!is_array($publications)) { throw new Exception('Failed to retrieve publications'); } // TODO : support different 'index' templates for different types of publications // (e.g. News, Sections, ...), depending on what "view" the user // selected (per category, per publication type, a combination, ...) ? if (!empty($owner)) { $data['author'] = xarUserGetVar('name', $owner); if (empty($data['author'])) { xarErrorHandled(); $data['author'] = xarML('Unknown'); } } if (!empty($pubdate)) { $data['pubdate'] = $pubdate; } // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Blocks.publications', 'ptid', $ptid); xarVarSetCached('Blocks.publications', 'cids', $cids); xarVarSetCached('Blocks.publications', 'owner', $owner); if (isset($data['author'])) { xarVarSetCached('Blocks.publications', 'author', $data['author']); } if (isset($data['pubdate'])) { xarVarSetCached('Blocks.publications', 'pubdate', $data['pubdate']); } // TODO: add this to publications configuration ? if ($ishome) { $data['ptid'] = null; if (xarSecurityCheck('SubmitPublications', 0)) { $data['submitlink'] = xarModURL('publications', 'admin', 'new'); } } else { $data['ptid'] = $ptid; if (!empty($ptid)) { $curptid = $ptid; } else { $curptid = 'All'; } if (count($cids) > 0) { foreach ($cids as $cid) { if (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:{$cid}:All:All")) { $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid, 'catid' => $catid)); break; } } } elseif (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:All:All:All")) { $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid)); } } $data['cids'] = $cids; $data['catid'] = $catid; xarVarSetCached('Blocks.categories', 'module', 'publications'); xarVarSetCached('Blocks.categories', 'itemtype', $ptid); xarVarSetCached('Blocks.categories', 'cids', $cids); if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) { xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']); // Note : this gets overriden by the categories navigation if necessary xarTplSetPageTitle(xarVarPrepForDisplay($pubtypes[$ptid]['description'])); } // optional category count if ($data['settings']['show_catcount']) { if (!empty($ptid)) { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'ptid' => $ptid)); if (isset($pubcatcount[$ptid])) { xarVarSetCached('Blocks.categories', 'catcount', $pubcatcount[$ptid]); } unset($pubcatcount); } else { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'reverse' => 1)); if (isset($pubcatcount) && count($pubcatcount) > 0) { $catcount = array(); foreach ($pubcatcount as $cat => $count) { $catcount[$cat] = $count['total']; } xarVarSetCached('Blocks.categories', 'catcount', $catcount); } unset($pubcatcount); } } else { // xarVarSetCached('Blocks.categories','catcount',array()); } // retrieve the number of comments for each article if (xarModIsAvailable('coments')) { if ($data['settings']['show_comments']) { $idlist = array(); foreach ($publications as $article) { $idlist[] = $article['id']; } $numcomments = xarModAPIFunc('comments', 'user', 'get_countlist', array('modid' => $c_modid, 'objectids' => $idlist)); } } // retrieve the keywords for each article if (xarModIsAvailable('coments')) { if ($data['settings']['show_keywords']) { $idlist = array(); foreach ($publications as $article) { $idlist[] = $article['id']; } $keywords = xarModAPIFunc('keywords', 'user', 'getmultiplewords', array('modid' => $c_modid, 'objectids' => $idlist, 'itemtype' => $ptid)); } } /* ------------------------------------------------------------ // retrieve the categories for each article $catinfo = array(); if ($show_categories) { $cidlist = array(); foreach ($publications as $article) { if (!empty($article['cids']) && count($article['cids']) > 0) { foreach ($article['cids'] as $cid) { $cidlist[$cid] = 1; } } } if (count($cidlist) > 0) { $catinfo = xarModAPIFunc('categories','user','getcatinfo', array('cids' => array_keys($cidlist))); // get root categories for this publication type // get base categories for all if needed $catroots = xarModAPIFunc('publications', 'user', 'getrootcats', array('ptid' => $ptid, 'all' => true) ); } foreach ($catinfo as $cid => $info) { $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']); $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => (($catid && $andcids) ? $catid . '+' . $cid : $cid) ) ); // only needed when sorting by root category id $catinfo[$cid]['root'] = 0; // means not found under a root category // only needed when sorting by root category order $catinfo[$cid]['order'] = 0; // means not found under a root category $rootidx = 1; foreach ($catroots as $rootcat) { // see if we're a child category of this rootcat (cfr. Celko model) if ($info['left'] >= $rootcat['catleft'] && $info['left'] < $rootcat['catright']) { // only needed when sorting by root category id $catinfo[$cid]['root'] = $rootcat['catid']; // only needed when sorting by root category order $catinfo[$cid]['order'] = $rootidx; break; } $rootidx++; } } // needed for sort function below $GLOBALS['artviewcatinfo'] = $catinfo; } $number = 0; foreach ($publications as $article) { // TODO: don't include ptid and catid if we don't use short URLs // link to article $article['link'] = xarModURL('publications', 'user', 'display', // don't include pubtype id if we're navigating by category array( 'ptid' => empty($ptid) ? null : $article['pubtype_id'], 'catid' => $catid, 'id' => $article['id'] ) ); // N words/bytes more in article if (!empty($article['body'])) { // note : this is only an approximate number $wordcount = count(preg_split("/\s+/", strip_tags($article['body']), -1, PREG_SPLIT_NO_EMPTY)); $article['words'] = $wordcount; // byte-count is less CPU-intensive -> make configurable ? $article['bytes'] = strlen($article['body']); } else { $article['words'] = 0; $article['bytes'] = 0; } // current publication type $curptid = $article['pubtype_id']; // TODO: make configurable? $article['redirect'] = xarModURL('publications', 'user', 'redirect', array('ptid' => $curptid, 'id' => $article['id']) ); // multi-column display (default from left to right, then from top to bottom) $article['number'] = $number; if (!empty($settings['number_of_columns'])) { $col = $number % $settings['number_of_columns']; } else { $col = 0; } // RSS Processing $current_theme = xarVarGetCached('Themes.name', 'CurrentTheme'); if (($current_theme == 'rss') or ($current_theme == 'atom')){ $article['rsstitle'] = htmlspecialchars($article['title']); //$article['rssdate'] = strtotime($article['date']); $article['rsssummary'] = preg_replace('<br />', "\n", $article['summary']); $article['rsssummary'] = xarVarPrepForDisplay(strip_tags($article['rsssummary'])); $article['rsscomment'] = xarModURL('comments', 'user', 'display', array('modid' => $c_modid, 'objectid' => $article['id'])); // $article['rsscname'] = htmlspecialchars($item['cname']); // <category>#$rsscname#</category> } // TODO: clean up depending on field format if ($do_transform) { $article['itemtype'] = $article['pubtype_id']; // TODO: what about transforming DD fields? if ($title_transform) { $article['transform'] = array('title', 'summary', 'body', 'notes'); } else { $article['transform'] = array('summary', 'body', 'notes'); } $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications'); } $data['titles'][$article['id']] = $article['title']; // fill in the summary template for this article $summary_template = $pubtypes[$article['pubtype_id']]['name']; $number++;echo $number; } ------------------------------------------------------------ */ unset($publications); // TODO: verify for other URLs as well if ($ishome) { if (!empty($numcols) && $numcols > 1) { // if we're currently showing more than 1 column $data['showcols'] = 1; } else { $defaultcols = $data['settings']['number_of_columns']; if ($defaultcols > 1) { // if the default number of columns is more than 1 $data['showcols'] = $defaultcols; } } } // Specific layout within a template (optional) if (isset($layout)) { $data['layout'] = $layout; } // Get the publications we want to view $data['object'] = DataObjectMaster::getObject(array('name' => $data['pubtypeobject']->properties['name']->value)); $data['objectname'] = $data['pubtypeobject']->properties['name']->value; $data['ptid'] = $ptid; // $object = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value)); // $data['items'] = $object->getItems(); $data['object'] = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value)); // Get the items here // $items = $data['object']->getItems(); /* We're doing this in the template now // Only show top level documents, not translations sys::import('xaraya.structures.query'); $q = new Query(); $q->eq('parent_id',0); $q->eq('pubtype_id',$ptid); $q->eq('state',3); // Suppress deleted items // Remove this once listing property works with dataobject access $q->ne('state',0); $data['conditions'] = $q; */ // Set the page template if needed if (!empty($data['settings']['page_template'])) { $pagename = $data['settings']['page_template']; $position = strpos($pagename, '.'); if ($position === false) { $pagetemplate = $pagename; } else { $pagetemplate = substr($pagename, 0, $position); } xarTpl::setPageTemplateName($pagetemplate); } // Throw all the relevant settings we are using into the cache // $data['settings']['pubtypeobject'] = $data['pubtypeobject']->properties['configuration']->getValue(); // xarCore::setCached('publications', 'context' . $ptid, $data['settings']); return xarTplModule('publications', 'user', 'view', $data, $data['template']); }
function publications_admin_update() { // Get parameters if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('items', 'str', $items, '', XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $data['ptid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('modify_cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('preview', 'isset', $data['preview'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('quit', 'isset', $data['quit'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('front', 'isset', $data['front'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code // This has been disabled for now // if (!xarSecConfirmAuthKey()) return; $items = explode(',', $items); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); // First we need to check all the data on the template // If checkInput fails, don't bail $itemsdata = array(); $isvalid = true; foreach ($items as $prefix) { $data['object']->setFieldPrefix($prefix); // Disable the celkoposition property according if this is not the base document $fieldname = $prefix . '_dd_' . $data['object']->properties['parent']->id; $data['object']->properties['parent']->checkInput($fieldname); if (empty($data['object']->properties['parent']->value)) { $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISPLAYONLY); } else { $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISABLED); } // Now get the input from the form $thisvalid = $data['object']->checkInput(); $isvalid = $isvalid && $thisvalid; // Store each item for later processing $itemsdata[$prefix] = $data['object']->getFieldValues(array(), 1); } if ($data['preview'] || !$isvalid) { // Show debug info if called for if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) { var_dump($data['object']->getInvalids()); } // Preview or bad data: redisplay the form $data['properties'] = $data['object']->getProperties(); if ($data['preview']) { $data['tab'] = 'preview'; } $data['items'] = $itemsdata; // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); return xarTplModule('publications', 'admin', 'modify', $data); } // call transform input hooks $article['transform'] = array('summary', 'body', 'notes'); $article = xarModCallHooks('item', 'transform-input', $data['itemid'], $article, 'publications', $data['ptid']); // Now talk to the database. Loop through all the translation pages foreach ($itemsdata as $id => $itemdata) { // Get the data for this item $data['object']->setFieldValues($itemdata, 1); // Save or create the item (depends whether this translation is new) if (empty($id)) { $item = $data['object']->createItem(); } else { $item = $data['object']->updateItem(); } // Check if we have an alias and set it as an alias of the publications module $alias_flag = $data['object']->properties['alias_flag']->value; if ($alias_flag == 1) { $alias = $data['object']->properties['alias']->value; if (!empty($alias)) { xarModAlias::set($alias, 'publications'); } } elseif ($alias_flag == 2) { $alias = $data['object']->properties['name']->value; if (!empty($alias)) { xarModAlias::set($alias, 'publications'); } } // Clear the itemid property in preparation for the next round unset($data['object']->itemid); } // Success xarSession::setVar('statusmsg', xarML('Publication Updated')); // If quitting, go to admin view; otherwise redisplay the page if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) { if ($data['quit']) { // Redirect if we came from somewhere else $current_listview = xarSession::getVar('publications_current_listview'); if (!empty($current_listview)) { xarController::redirect($current_listview); } xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid']))); } elseif ($data['front']) { xarController::redirect(xarModURL('publications', 'user', 'display', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid']))); } else { xarController::redirect(xarModURL('publications', 'admin', 'modify', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid']))); } return true; } }
/** * New account info (ship address) */ function shop_user_shippingaddress() { // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be $shop = xarSession::getVar('shop'); if (!xarUserIsLoggedIn() || empty($shop)) { xarResponse::redirect(xarModURL('shop', 'user', 'main')); return true; } if (!xarVarFetch('proceed', 'str', $proceed, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('shipto', 'str', $shipto, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('remove', 'str', $remove, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('next', 'str', $data['next'], NULL, XARVAR_NOT_REQUIRED)) { return; } sys::import('modules.dynamicdata.class.objects.master'); $data['shippingobject'] = DataObjectMaster::getObject(array('name' => 'shop_shippingaddresses')); $data['shippingobject']->properties['name']->display_show_salutation = false; $data['shippingobject']->properties['name']->display_show_middlename = false; $data['shippingobject']->properties['address']->display_rows = 1; $data['shippingobject']->properties['address']->display_show_country = false; $data['properties'] = $data['shippingobject']->properties; if ($shipto) { xarSession::setVar('shippingaddress', $shipto); if (isset($data['next']) && !empty($data['next'])) { $func = $data['next']; } else { $func = 'paymentmethod'; } xarResponse::redirect(xarModURL('shop', 'user', $func)); return true; } if ($remove) { if ($remove == xarSession::getVar('shippingaddress')) { xarSession::delVar('shippingaddress'); } $data['shippingobject']->getItem(array('itemid' => $remove)); $data['shippingobject']->deleteItem(); xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress')); return true; } if ($proceed) { $isvalid = $data['shippingobject']->checkInput(); if (!$isvalid) { return xarTplModule('shop', 'user', 'shippingaddress', $data); } // Save the customer data $custobject = DataObjectMaster::getObject(array('name' => 'shop_customers')); $custobject->getItem(array('itemid' => xarUserGetVar('id'))); $name = $data['shippingobject']->properties['name']->value; $custobject->properties['name']->setValue($name); $custobject->updateItem(); // Save the shipping address $itemid = $data['shippingobject']->createItem(); xarSession::setVar('shippingaddress', $itemid); // update the name field in roles to use first and last name instead of email $rolesobject = xarCurrentRole(); $rolesobject->properties['name']->value = $name; $rolesobject->updateItem(); xarResponse::redirect(xarModURL('shop', 'user', 'paymentmethod')); return true; xarSession::setVar('errors', $errors); } return $data; }