Beispiel #1
0
/**
 *  Get products
 */
function shop_userapi_getproducts($args)
{
    $startnum = 1;
    extract($args);
    if (!xarSecurityCheck('ViewShop')) {
        return;
    }
    if (!isset($items_per_page)) {
        $items_per_page = xarModVars::get('shop', 'items_per_page');
    }
    $data['items_per_page'] = $items_per_page;
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    sys::import('modules.dynamicdata.class.properties.master');
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_products'));
    $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'id', 'ascdesc_fallback' => 'ASC'));
    // We have some filters for the items
    $filters = array('startnum' => $startnum, 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']);
    if (isset($where)) {
        $filters['where'] = $where;
    }
    // Get the items
    $products = $mylist->getItems($filters);
    // return the products
    $data['products'] = $products;
    // Return the template variables defined in this function
    return $data;
}
Beispiel #2
0
function publications_user_new($args)
{
    extract($args);
    // Get parameters
    if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) {
        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));
    $data['properties'] = $data['object']->getProperties();
    if (!empty($data['ptid'])) {
        $template = $pubtypeobject->properties['template']->value;
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    // Get the settings of the publication type we are using
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    return xarTplModule('publications', 'admin', 'new', $data, $template);
}
Beispiel #3
0
function calendar_admin_add_event()
{
    // Security check
    if (!xarSecurityCheck('Admincalendar')) {
        return;
    }
    // Generate a one-time authorisation code for this operation
    $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars');
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    // Variables from phpIcalendar config.inc.php
    $data['updatebutton'] = xarVarPrepForDisplay(xarML('Create event'));
    //TODO: should I include this stuff? --amoro
    /*    $hooks = xarModCallHooks('module', 'modifyconfig', 'calendar',
            array('module' => 'calendar'));
        if (empty($hooks)) {
            $data['hooks'] = '';
        } elseif (is_array($hooks)) {
            $data['hooks'] = join('', $hooks);
        } else {
            $data['hooks'] = $hooks;
        }
    */
    // Return the template variables defined in this function
    return $data;
}
Beispiel #4
0
function publications_admin_templates_page($args)
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    extract($args);
    if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('ptid', 'id', $data['ptid'], 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemid', 'id', $data['itemid'], 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('file', 'str', $data['file'], 'summary', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (empty($data['itemid']) || empty($data['ptid'])) {
        return xarResponse::NotFound();
    }
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $pubtype = explode('_', $pubtypeobject->properties['name']->value);
    $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0];
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $basepath = sys::code() . "modules/publications/xartemplates/objects/" . $pubtype;
    $sourcefile = $basepath . "/" . $data['file'] . "_" . $data['itemid'] . ".xt";
    $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/objects/" . $pubtype;
    $overridefile = $overridepath . "/" . $data['file'] . "-" . $data['itemid'] . ".xt";
    // If we are saving, write the file now
    if ($confirm && !empty($data['source_data'])) {
        xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data']));
    }
    // Let the template know what kind of file this is
    if (file_exists($overridefile)) {
        $data['filetype'] = 'theme';
        $filepath = $overridefile;
        $data['writable'] = is_writable($overridefile);
    } else {
        $data['filetype'] = 'module';
        $filepath = $sourcefile;
        $data['writable'] = is_writeable_dir($overridepath);
    }
    $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath)));
    // Initialize the template
    if (empty($data['source_data'])) {
        $data['source_data'] = '<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout">';
        $data['source_data'] .= "\n";
        $data['source_data'] .= "\n" . '</xar:template>';
    }
    $data['files'] = array(array('id' => 'summary', 'name' => 'summary display'), array('id' => 'detail', 'name' => 'detail display'));
    return $data;
}
Beispiel #5
0
/**
 *  List the product attributes 
 */
function shop_admin_attributes()
{
    if (!xarVarFetch('startnum', 'isset', $data['startnum'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('user_id', 'isset', $user_id, NULL, XARVAR_DONT_SET)) {
        return;
    }
    $objectname = 'shop_attributes';
    $data['objectname'] = $objectname;
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!xarSecurityCheck('AdminShop')) {
        return;
    }
    $data['items_per_page'] = xarModVars::get('shop', 'items_per_page');
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object label for the template
    $object = DataObjectMaster::getObject(array('name' => $objectname));
    $data['label'] = $object->label;
    // Get the fields to display in the admin interface
    $config = $object->configuration;
    if (!empty($config['adminfields'])) {
        $data['adminfields'] = $config['adminfields'];
    } else {
        $data['adminfields'] = array_keys($object->getProperties());
    }
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => $objectname));
    // Load the DD master property class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.properties.master');
    $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'ID', 'ascdesc_fallback' => 'ASC'));
    // We have some filters for the items
    $filters = array('startnum' => $data['startnum'], 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']);
    if (isset($user_id)) {
        $filters['where'] = 'user_id eq ' . $user_id;
    }
    // Get the items
    $items = $mylist->getItems($filters);
    if (isset($user_id)) {
        // Get the object we'll be working with. Note this is a so called object list
        $mylist2 = DataObjectMaster::getObjectList(array('name' => 'shop_customers'));
        $filters = array();
        if (isset($user_id)) {
            $filters['where'] = 'ID eq ' . $user_id;
        }
        $items2 = $mylist2->getItems($filters);
        $data['fname'] = $items2[$user_id]['FirstName'];
        $data['lname'] = $items2[$user_id]['LastName'];
    }
    $data['mylist'] = $mylist;
    // Return the template variables defined in this function
    return $data;
}
Beispiel #6
0
/**
 *  Used to get the current view the calendar is in (Day, Week, Month, Year)
 */
function calendar_userapi_currentView()
{
    xarVarFetch('func', 'str::', $func, 'main', XARVAR_NOT_REQUIRED);
    $valid = array('day', 'week', 'month', 'year');
    $func = strtolower($func);
    if (!in_array($func, $valid)) {
        return xarModVars::get('calendar', 'default_view');
    } else {
        return $func;
    }
}
Beispiel #7
0
function publications_admin_stylesheet_type($args)
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    extract($args);
    if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('file', 'str', $data['file'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $pubtype = explode('_', $pubtypeobject->properties['name']->value);
    $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0];
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $basepath = sys::code() . "modules/publications/xarstyles";
    $sourcefile = $basepath . "/" . $data['file'] . ".css";
    $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/style";
    $overridefile = $overridepath . "/" . $data['file'] . ".css";
    // If we are saving, write the file now
    if ($confirm && !empty($data['file']) && !empty($data['source_data'])) {
        xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data']));
    }
    // Let the template know what kind of file this is
    if (empty($data['file'])) {
        $data['filetype'] = 'empty';
        $filepath = '';
        $data['writable'] = 0;
    } elseif (file_exists($overridefile)) {
        $data['filetype'] = 'theme';
        $filepath = $overridefile;
        $data['writable'] = is_writable($overridefile);
    } elseif (file_exists($sourcefile)) {
        $data['filetype'] = 'module';
        $filepath = $sourcefile;
        $data['writable'] = is_writeable_dir($overridepath);
    } else {
        $data['filetype'] = 'unknown';
        $filepath = $overridefile;
        $data['writable'] = is_writeable_dir($overridepath);
    }
    $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath)));
    return $data;
}
Beispiel #8
0
function calendar_admin_view_calendars()
{
    // Security check
    if (!xarSecurityCheck('Admincalendar')) {
        return;
    }
    // Generate a one-time authorisation code for this operation
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    // Return the template variables defined in this function
    $data['calendars'] = xarMod::apiFunc('calendar', 'user', 'getall');
    return $data;
}
Beispiel #9
0
/**
 * Main admin GUI function, entry point
 *
 */
function wurfl_admin_main()
{
    if (!xarSecurityCheck('ManageWurfl')) {
        return;
    }
    if (xarModVars::get('modules', 'disableoverview') == 0) {
        return array();
    } else {
        xarController::redirect(xarModURL('wurfl', 'admin', 'modifyconfig'));
    }
    // success
    return true;
}
Beispiel #10
0
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;
}
Beispiel #11
0
function shop_adminapi_handlepgresponse($args)
{
    extract($args);
    $pg = xarModVars::get('shop', 'payment_gateway');
    $trans_id = false;
    $pg_response = xarSession::getVar('pg_response');
    switch ($pg) {
        case 1:
            // demo mode
            $trans_id = rand(1000, 99999999);
            // fake trans id
            break;
        case 2:
            // authorize.net
            $response = xarMod::APIFunc('shop', 'admin', 'authorizenet', $transfields);
            if ($response[1] == 1) {
                $trans_id = $response[7];
            } else {
                $num = $response[1];
                $authorizenet_codes = array(1 => 'Approved', 2 => 'Declined', 3 => 'Error', 4 => 'Held for Review');
                $msg = $response[4];
                $msg .= ' Response code: ' . $authorizenet_codes[$num];
                $pg_response['msg'] = $msg;
            }
            break;
        case 3:
            // paypal web payments pro
            $args['transfields'] = $transfields;
            $args['methodName_'] = 'DoDirectPayment';
            $response = xarMod::APIFunc('shop', 'admin', 'paypal', $args);
            if ($response['ACK'] == 'Success') {
                $trans_id = $response['TRANSACTIONID'];
            } else {
                $msg = $response['ACK'];
                $msg .= '. Response: ' . urldecode($response['L_LONGMESSAGE0']);
                $pg_response['msg'] = $msg;
            }
            break;
        case 4:
            // something else
            // your code
            break;
    }
    if (isset($pg_response)) {
        xarSession::setVar('pg_response', $pg_response);
    }
    $response['trans_id'] = $trans_id;
    return $response;
}
Beispiel #12
0
 function display(array $data = array())
 {
     $data = parent::display($data);
     if (!defined('CALENDAR_ROOT')) {
         define('CALENDAR_ROOT', xarModVars::get('calendar', 'pearcalendar_root'));
     }
     include_once CALENDAR_ROOT . 'Month/Weekdays.php';
     include_once CALENDAR_ROOT . 'Decorator/Textual.php';
     sys::import("modules.calendar.class.Calendar.Decorator.Xaraya");
     // Build the month
     $data['content'] = xarMod::apiFunc('calendar', 'user', 'getuserdatetimeinfo');
     $data['content']['MonthCal'] = new Calendar_Month_Weekdays($data['content']['cal_year'], $data['content']['cal_month'], CALENDAR_FIRST_DAY_OF_WEEK);
     $data['content']['MonthCal']->build();
     return $data;
 }
Beispiel #13
0
 function createItem(array $args = array())
 {
     // Save the access property
     $this->properties['access']->setInputStatus(DataPropertyMaster::DD_INPUTSTATE_ADDMODIFY);
     // If multilanguages is not enabled just save the default language value
     if (!xarModVars::get('publications', 'multilanguage')) {
         if (isset($this->properties['locale'])) {
             $this->properties['locale']->setInputStatus(DataPropertyMaster::DD_INPUTSTATE_ADDMODIFY);
         }
     }
     // Ignore the position if this isn't the base document
     if (empty($this->properties['parent']->value)) {
         $this->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISPLAYONLY);
     } else {
         $this->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISABLED);
     }
     $this->fieldlist = array();
     return parent::createItem($args);
 }
Beispiel #14
0
function calendar_admin_add_calendars()
{
    // Security check
    //    if (!xarSecurityCheck('AddCalendar',0,'Calendar')) return;
    if (!xarVarFetch('calid', 'int:0:', $calid, '0', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('calname', 'str', $calname, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars');
    // Generate a one-time authorisation code for this operation
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    $data['addbutton'] = xarVarPrepForDisplay(xarML('Add calendar'));
    $data['message'] = xarVarPrepForDisplay(xarML('Created calendar with name "#(1)", ID #(2)', $calname, $calid));
    $data['calid'] = $calid;
    return $data;
}
Beispiel #15
0
function calendar_user_month()
{
    $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo');
    $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'] + 1, xarModVars::get('calendar', 'cal_sdow'));
    $end_time = $MonthEvents->getTimestamp();
    $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'], xarModVars::get('calendar', 'cal_sdow'));
    $start_time = $MonthEvents->getTimestamp();
    $q = new Query('SELECT');
    $a[] = $q->plt('start_time', $start_time);
    $a[] = $q->pge('start_time + duration', $start_time);
    $b[] = $q->plt('start_time', $end_time);
    $b[] = $q->pge('start_time + duration', $end_time);
    $c[] = $q->pgt('start_time', $start_time);
    $c[] = $q->ple('start_time + duration', $end_time);
    $d[] = $q->pqand($a);
    $d[] = $q->pqand($b);
    $d[] = $q->pqand($c);
    $q->qor($d);
    $q->eq('role_id', xarSession::getVar('role_id'));
    $data['conditions'] = $q;
    return $data;
}
Beispiel #16
0
/**
 *  Connect to authorize.net
 */
function shop_adminapi_authorizenet($args)
{
    extract($args);
    $post_url = "https://test.authorize.net/gateway/transact.dll";
    $post_values = array("x_login" => xarModVars::get('shop', 'pg_id'), "x_tran_key" => xarModVars::get('shop', 'pg_key'), "x_version" => "3.1", "x_delim_data" => "TRUE", "x_delim_char" => "|", "x_relay_response" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_card_num" => $card_num, "x_exp_date" => $exp_date, "x_amount" => $total, "x_description" => $products, "x_first_name" => $first_name, "x_last_name" => $last_name, "x_address" => $street_addr, "x_state" => $state_addr, "x_zip" => $postal_code);
    // This section takes the input fields and converts them to the proper format
    // for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
    $post_string = "";
    foreach ($post_values as $key => $value) {
        $post_string .= "{$key}=" . urlencode($value) . "&";
    }
    $post_string = rtrim($post_string, "& ");
    // This sample code uses the CURL library for php to establish a connection,
    // submit the post, and record the response.
    // If you receive an error, you may want to ensure that you have the curl
    // library enabled in your php configuration
    $request = curl_init($post_url);
    // initiate curl object
    curl_setopt($request, CURLOPT_HEADER, 0);
    // set to 0 to eliminate header info from response
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
    // Returns response data instead of TRUE(1)
    curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
    // use HTTP POST to send form data
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
    // uncomment this line if you get no gateway response.
    $post_response = curl_exec($request);
    // execute curl post and store results in $post_response
    // additional options may be required depending upon your server configuration
    // you can find documentation on curl options at http://www.php.net/curl_setopt
    curl_close($request);
    // close curl object
    $array = array(0 => '');
    // This line takes the response and breaks it into an array using the specified delimiting character
    $response_array = explode($post_values["x_delim_char"], $post_response);
    //to make things consistent with the authorize.net documentation, we want the authorize.net values to start with a key of 1
    $response_array = array_merge($array, $response_array);
    return $response_array;
}
Beispiel #17
0
 /**
  * Display func.
  * @param $blockinfo array
  * @returns $blockinfo array
  */
 function display(array $data = array())
 {
     $data = parent::display($data);
     if (empty($data)) {
         return;
     }
     if (!defined('CALENDAR_ROOT')) {
         define('CALENDAR_ROOT', xarModVars::get('calendar', 'pearcalendar_root'));
     }
     include_once CALENDAR_ROOT . 'Calendar.php';
     $tplData['form_action'] = xarModURL('calendar', 'user', 'changecalnav');
     $tplData['blockid'] = $data['bid'];
     if (xarServer::getVar('REQUEST_METHOD') == 'GET') {
         // URL of this page
         $tplData['return_url'] = xarServer::getCurrentURL();
     } else {
         // Base URL of the site
         $tplData['return_url'] = xarServer::getBaseURL();
     }
     $data['content'] = $tplData;
     return $data;
 }
Beispiel #18
0
 public function setup($timeframe, $role_id)
 {
     $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo');
     switch ($timeframe) {
         case 'week':
             $WeekEvents = new Calendar_Week($data['cal_year'], $data['cal_month'], $data['cal_day'], CALENDAR_FIRST_DAY_OF_WEEK);
             $start_time = $WeekEvents->thisWeek;
             $end_time = $WeekEvents->nextWeek;
             $events = $this->getEvents($start_time, $end_time, $role_id);
             $WeekDecorator = new WeekEvent_Decorator($WeekEvents);
             $WeekDecorator->build($events);
             $data['Week'] =& $WeekDecorator;
             $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK;
             break;
         case 'month':
             $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'] + 1, xarModVars::get('calendar', 'cal_sdow'));
             $end_time = $MonthEvents->getTimestamp();
             $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'], xarModVars::get('calendar', 'cal_sdow'));
             $start_time = $MonthEvents->getTimestamp();
             $events = $this->getEvents($start_time, $end_time, $role_id);
             $MonthDecorator = new MonthEvent_Decorator($MonthEvents);
             $MonthDecorator->build($events);
             $data['Month'] =& $MonthDecorator;
             break;
         case 'year':
             $Year = new Calendar_Year($data['cal_year'] + 1);
             $end_time = $Year->getTimestamp();
             $Year = new Calendar_Year($data['cal_year']);
             $start_time = $Year->getTimestamp();
             $events = $this->getEvents($start_time, $end_time, $role_id);
             $YearDecorator = new YearEvent_Decorator($Year);
             $YearDecorator->build($events);
             $data['Year'] =& $YearDecorator->calendar;
             $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK;
             break;
     }
     return $data;
 }
Beispiel #19
0
<?php

include "usaepaylib.php";
$tran = new umTransaction();
$tran->key = xarModVars::get('shop', 'pg_key');
$tran->ip = $_SERVER['REMOTE_ADDR'];
// This allows fraud blocking on the customers ip address
$tran->usesandbox = true;
$tran->ignoresslcerterrors = true;
$tran->card = "4000200011112222";
// card number, no dashes, no spaces
$tran->exp = "1212";
// expiration date 4 digits no /
$tran->amount = "1.00";
// charge amount in dollars
$tran->invoice = "1234";
// invoice number.  must be unique.
$tran->cardholder = "Test T Jones";
// name of card holder
$tran->street = "1234 Main Street";
// street address
$tran->zip = "05673";
// zip code
$tran->description = "Online Order";
// description of charge
$tran->cvv2 = "435";
// cvv2 code
echo "<h1>Please wait one moment while we process your card...<br>\n";
flush();
if ($tran->Process()) {
    echo "<b>Card Approved</b><br>";
Beispiel #20
0
/**
 * get an array of root categories with links
 *
 * @param int $args['ptid'] publication type ID
 * @param $args['all'] boolean if we need to return all root categories when
 *                     ptid is empty (default false)
 * @return array
 * @TODO specify return format
 */
function publications_userapi_getrootcats($args)
{
    extract($args);
    if (empty($ptid) || !is_numeric($ptid)) {
        $ptid = null;
    }
    // see which root categories we need to handle
    $rootcats = array();
    if (!empty($ptid)) {
        $rootcats = unserialize(xarModUserVars::get('publications', 'basecids', $ptid));
    } elseif (empty($all)) {
        $rootcats = unserialize(xarModVars::get('publications', 'basecids'));
    } else {
        // Get publication types
        $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
        // get base categories for all publication types here
        $publist = array_keys($pubtypes);
        // add the defaults too, in case we have other base categories there
        $publist[] = '';
        // build the list of root categories for all required publication types
        $catlist = array();
        foreach ($publist as $pubid) {
            if (empty($pubid)) {
                $cidstring = xarModVars::get('publications', 'basecids');
            } else {
                $cidstring = xarModUserVars::get('publications', 'basecids', $pubid);
            }
            if (!empty($cidstring)) {
                $rootcats = unserialize($cidstring);
            } else {
                $rootcats = array();
            }
            foreach ($rootcats as $cid) {
                $catlist[$cid] = 1;
            }
        }
        if (count($catlist) > 0) {
            $rootcats = array_keys($catlist);
        }
    }
    if (empty($rootcats)) {
        $rootcats = array();
    }
    if (count($rootcats) < 1) {
        return array();
    }
    if (!xarModAPILoad('categories', 'user')) {
        return;
    }
    $isfirst = 1;
    $catlinks = array();
    $catlist = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => $rootcats));
    if (empty($catlist)) {
        return $catlinks;
    }
    // preserve order of root categories if possible
    foreach ($rootcats as $cid) {
        if (!isset($catlist[$cid])) {
            continue;
        }
        $info = $catlist[$cid];
        $item = array();
        $item['catid'] = $info['cid'];
        $item['cattitle'] = xarVarPrepForDisplay($info['name']);
        $item['catlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid']));
        if ($isfirst) {
            $item['catjoin'] = '';
            $isfirst = 0;
        } else {
            $item['catjoin'] = ' | ';
        }
        $item['catleft'] = $info['left'];
        $item['catright'] = $info['right'];
        $catlinks[] = $item;
    }
    return $catlinks;
}
Beispiel #21
0
/**
 * Get pages relative to a given page
 *
 * Filters:
 * Add an arg of the type $args['filter_foo'] = bar
 * will add a condition to the SELECT as
 * WHERE foo = bar
 *
 */
function publications_userapi_get_sitemap_pages($args)
{
    if (empty($args['itemid'])) {
        $args['itemid'] = 0;
    }
    if (empty($args['scope'])) {
        $args['scope'] = 'descendants';
    }
    if ($args['itemid'] == 0 && $args['scope'] == 'descendants') {
        $args['scope'] = 'all';
    }
    if (empty($args['sort'])) {
        $args['sort'] = 0;
    }
    // Make sure we have the base translation id
    if (!empty($args['itemid'])) {
        $args['itemid'] = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $args['itemid'], 'locale' => xarModVars::get('publications', 'defaultlanguage')));
    }
    // Identify any filters
    $filters = array();
    foreach ($args as $k => $v) {
        if (strpos($k, 'filter_') === 0) {
            $argname = substr($k, 7);
            $filters[$argname] = $v;
        }
    }
    $xartable = xarDB::getTables();
    sys::import('xaraya.structures.query');
    $q = new Query();
    $q->addtable($xartable['publications'], 'p');
    switch ($args['scope']) {
        case 'all':
            $q->gt('p.leftpage_id', 0);
            break;
        case 'descendants':
            $q->addtable($xartable['publications'], 'root');
            $q->eq('root.id', $args['itemid']);
            $q->le('root.leftpage_id', 'expr:p.leftpage_id');
            $q->ge('root.rightpage_id', 'expr:p.rightpage_id');
            break;
        case 'children':
            $q->eq('p.parentpage_id', $args['itemid']);
            break;
        case 'siblings':
            $q->addtable($xartable['publications'], 'p1');
            $q->join('p.parentpage_id', 'p1.parentpage_id');
            $q->eq('p1.id', $args['itemid']);
            break;
    }
    if (!empty($args['itemtype'])) {
        $q->eq('p.pubtype_id', $args['itemtype']);
    }
    $q->eq('p.sitemap_flag', 1);
    $q->gt('p.state', 2);
    $q->addfield('p.id AS id');
    $q->addfield('p.name AS name');
    $q->addfield('p.title AS title');
    $q->addfield('p.description AS description');
    $q->addfield('p.sitemap_source_flag AS sitemap_source_flag');
    $q->addfield('p.sitemap_alias AS sitemap_alias');
    $q->addfield('p.pubtype_id AS pubtype_id');
    $q->addfield('p.rightpage_id AS rightpage_id');
    // Add any fiters we found
    foreach ($filters as $k => $v) {
        $q->eq('p.' . $k, $v);
    }
    // We can force alpha sorting, or else sort according to tree position
    if ($args['sort']) {
        $q->setorder('p.title');
    } else {
        $q->setorder('p.leftpage_id');
    }
    //    $q->qecho();
    $q->run();
    $pages = $q->output();
    $depthstack = array();
    foreach ($pages as $key => $page) {
        // Calculate the relative nesting level.
        // 'depth' is 0-based. Top level (root node) is zero.
        if (!empty($depthstack)) {
            while (!empty($depthstack) && end($depthstack) < $page['rightpage_id']) {
                array_pop($depthstack);
            }
        }
        $depthstack[$page['id']] = $page['rightpage_id'];
        $pages[$key]['depth'] = empty($depthstack) ? 0 : count($depthstack) - 1;
        // This item is the path for each page, based on page IDs.
        // It is effectively a list of ancestor IDs for a page.
        // FIXME: some paths seem to get a '0' root ID. They should only have real page IDs.
        $pages[$key]['idpath'] = array_keys($depthstack);
        $pathstack[$key] = $page['name'];
        // This item is the path for each page, based on names.
        // Imploding it can give a directory-style path, which is handy
        // in admin pages and reports.
        $pages[$key]['namepath'] = $pathstack;
    }
    // If we are looking for translations rather than base documents, then find what translations are available and substitute them
    // CHECKME: is there a better way?
    // If there is no translation the base document remains. Is this desired outcome?
    if (!empty($pages) && xarModVars::get('publications', 'defaultlanguage') != xarUserGetNavigationLocale()) {
        $indexedpages = array();
        foreach ($pages as $v) {
            $indexedpages[$v['id']] = $v;
        }
        $ids = array_keys($indexedpages);
        $q = new Query();
        $q->addtable($xartable['publications']);
        $q->addfield('id');
        $q->addfield('parent_id');
        $q->addfield('name');
        $q->addfield('title');
        $q->addfield('description');
        $q->addfield('sitemap_source_flag');
        $q->addfield('sitemap_alias');
        $q->addfield('pubtype_id');
        $q->in('parent_id', $ids);
        $q->eq('locale', xarUserGetNavigationLocale());
        // Add any fiters we found
        foreach ($filters as $k => $v) {
            $q->eq($k, $v);
        }
        $q->run();
        foreach ($q->output() as $row) {
            // Copy the name and id paths so we don't have to recalculate them
            $row['depth'] = $indexedpages[$row['parent_id']]['depth'];
            $row['idpath'] = $indexedpages[$row['parent_id']]['idpath'];
            $row['namepath'] = $indexedpages[$row['parent_id']]['namepath'];
            // Add the entire row to the result pages
            $indexedpages[$row['parent_id']] = $row;
        }
        $pages =& $indexedpages;
    }
    return $pages;
}
Beispiel #22
0
/**
 * search publications (called as hook from search module, or directly with pager)
 *
 * @param $args['objectid'] could be the query ? (currently unused)
 * @param $args['extrainfo'] all other parameters ? (currently unused)
 * @return array output
 */
function publications_user_search($args)
{
    // pager stuff
    if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // categories stuff
    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;
    }
    // single publication type when called via the pager
    if (!xarVarFetch('ptid', 'id', $ptid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // multiple publication types when called via search hooks
    if (!xarVarFetch('ptids', 'array', $ptids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // date stuff via forms
    if (!xarVarFetch('publications_startdate', 'str', $startdate, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('publications_enddate', 'str', $enddate, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // date stuff via URLs
    if (!xarVarFetch('start', 'int:0', $start, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('end', 'int:0', $end, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // search button was pressed
    if (!xarVarFetch('search', 'str', $search, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // select by article state (array or string)
    if (!xarVarFetch('state', 'isset', $state, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // yes, this is the query
    if (!xarVarFetch('q', 'str', $q, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('author', 'str', $author, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // filter by category
    if (!xarVarFetch('by', 'str', $by, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // can't use list enum here, because we don't know which sorts might be used
    if (!xarVarFetch('sort', 'regexp:/^[\\w,]*$/', $sort, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // boolean AND/OR for words (no longer used)
    //if(!xarVarFetch('bool',     'str',   $bool,   NULL, XARVAR_NOT_REQUIRED)) {return;}
    // search in specific fields
    if (!xarVarFetch('publications_fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('searchtype', 'isset', $searchtype, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (isset($args['objectid'])) {
        $ishooked = 1;
    } else {
        $ishooked = 0;
        if (empty($fields)) {
            // search in specific fields via URLs
            if (!xarVarFetch('fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) {
                return;
            }
        }
    }
    // TODO: could we need this someday ?
    if (isset($args['extrainfo'])) {
        extract($args['extrainfo']);
    }
    // TODO: clean up this copy & paste stuff :-)
    // Default parameters
    if (!isset($startnum)) {
        $startnum = 1;
    }
    if (!isset($numitems)) {
        $numitems = 20;
    }
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    // Get publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    if (xarSecurityCheck('AdminPublications', 0)) {
        $isadmin = true;
    } else {
        $isadmin = false;
    }
    // frontpage or approved state
    if (!$isadmin || !isset($state)) {
        $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED);
    } elseif (is_string($state)) {
        if (strpos($state, ' ')) {
            $state = explode(' ', $state);
        } elseif (strpos($state, '+')) {
            $state = explode('+', $state);
        } else {
            $state = array($state);
        }
    }
    $seenstate = array();
    foreach ($state as $that) {
        if (empty($that) || !is_numeric($that)) {
            continue;
        }
        $seenstate[$that] = 1;
    }
    $state = array_keys($seenstate);
    if (count($state) != 2 || !in_array(PUBLICATIONS_STATE_APPROVED, $state) || !in_array(PUBLICATIONS_STATE_FRONTPAGE, $state)) {
        $stateline = implode('+', $state);
    } else {
        $stateline = null;
    }
    if (!isset($sort)) {
        $sort = null;
    }
    // default publication type(s) to search in
    if (!empty($ptid) && isset($pubtypes[$ptid])) {
        $ptids = array($ptid);
        $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid));
        if (empty($settings['show_categories'])) {
            $show_categories = 0;
        } else {
            $show_categories = 1;
        }
    } elseif (!empty($ptids) && count($ptids) > 0) {
        foreach ($ptids as $curptid) {
            // default view doesn't apply here ?!
        }
        $show_categories = 1;
    } elseif (!isset($ptids)) {
        //    $ptids = array(xarModVars::get('publications','defaultpubtype'));
        $ptids = array();
        foreach ($pubtypes as $pubid => $pubtype) {
            $ptids[] = $pubid;
        }
        $show_categories = 1;
    } else {
        // TODO: rethink this when we're dealing with multi-pubtype categories
        $show_categories = 0;
    }
    // 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;
        } else {
            $cids = explode('-', $catid);
            $andcids = false;
        }
    }
    $seencid = array();
    $catid = null;
    if (isset($cids) && is_array($cids)) {
        foreach ($cids as $cid) {
            if (empty($cid) || !preg_match('/^_?[0-9]+$/', $cid)) {
                continue;
            }
            $seencid[$cid] = 1;
        }
        $cids = array_keys($seencid);
        if ($andcids) {
            $catid = join('+', $cids);
        } else {
            $catid = join('-', $cids);
        }
    }
    $seenptid = array();
    if (isset($ptids) && is_array($ptids)) {
        foreach ($ptids as $curptid) {
            if (empty($curptid) || !isset($pubtypes[$curptid])) {
                continue;
            }
            $seenptid[$curptid] = 1;
        }
        $ptids = array_keys($seenptid);
    }
    /* Ensure whitespace alone not passed to api -causes errors */
    if (isset($q) && trim($q) === '') {
        $q = null;
    }
    // Find the id of the author we're looking for
    if (!empty($author)) {
        // Load API
        if (!xarModAPILoad('roles', 'user')) {
            return;
        }
        $user = xarModAPIFunc('roles', 'user', 'get', array('name' => $author));
        if (!empty($user['uid'])) {
            $owner = $user['uid'];
        } else {
            $owner = null;
            $author = null;
        }
    } else {
        $owner = null;
        $author = null;
    }
    if (isset($start) && is_numeric($start)) {
        $startdate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $start);
    }
    if (isset($end) && is_numeric($end)) {
        $enddate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $end);
    }
    if (empty($fields)) {
        $fieldlist = array('title', 'description', 'summary', 'body1');
    } else {
        $fieldlist = array_keys($fields);
        // don't pass fields via URLs if we stick to the default list
        if (count($fields) == 3 && isset($fields['title']) && isset($fields['description']) && isset($fields['summary']) && isset($fields['body1'])) {
            $fields = null;
        }
    }
    // Set default searchtype to 'fulltext' if necessary
    $fulltext = xarModVars::get('publications', 'fulltextsearch');
    if (!isset($searchtype) && !empty($fulltext)) {
        $searchtype = 'fulltext';
    }
    // FIXME: fulltext only supports searching in all configured text fields !
    if (empty($fields) && !empty($fulltext) && !empty($searchtype) && $searchtype == 'fulltext') {
        $fieldlist = explode(',', $fulltext);
    }
    $data = array();
    $data['results'] = array();
    $data['state'] = '';
    $data['ishooked'] = $ishooked;
    // TODO: MichelV: $ishooked is never empty, but either 0 or 1
    if (empty($ishooked)) {
        $data['q'] = isset($q) ? xarVarPrepForDisplay($q) : null;
        $data['author'] = isset($author) ? xarVarPrepForDisplay($author) : null;
        $data['searchtype'] = $searchtype;
    }
    if ($isadmin) {
        $states = xarModAPIFunc('publications', 'user', 'getstates');
        $data['statelist'] = array();
        foreach ($states as $id => $name) {
            $data['statelist'][] = array('id' => $id, 'name' => $name, 'checked' => in_array($id, $state));
        }
    }
    // TODO: show field labels when we're dealing with only 1 pubtype
    $data['fieldlist'] = array(array('id' => 'title', 'name' => xarML('title'), 'checked' => in_array('title', $fieldlist)), array('id' => 'description', 'name' => xarML('description'), 'checked' => in_array('description', $fieldlist)), array('id' => 'summary', 'name' => xarML('summary'), 'checked' => in_array('summary', $fieldlist)), array('id' => 'body1', 'name' => xarML('body1'), 'checked' => in_array('body1', $fieldlist)), array('id' => 'notes', 'name' => xarML('notes'), 'checked' => in_array('notes', $fieldlist)));
    $data['publications'] = array();
    foreach ($pubtypes as $pubid => $pubtype) {
        if (!empty($seenptid[$pubid])) {
            $checked = ' checked="checked"';
        } else {
            $checked = '';
        }
        $data['publications'][] = array('id' => $pubid, 'description' => xarVarPrepForDisplay($pubtype['description']), 'checked' => $checked);
    }
    $data['categories'] = array();
    if (!empty($by) && $by == 'cat') {
        $catarray = array();
        foreach ($ptids as $curptid) {
            // get root categories for this publication type
            $catlinks = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid));
            foreach ($catlinks as $cat) {
                $catarray[$cat['category_id']] = $cat['name'];
            }
        }
        foreach ($catarray as $cid => $title) {
            $select = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $cid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1));
            $data['categories'][] = array('cattitle' => $title, 'catselect' => $select);
        }
        $data['searchurl'] = xarModURL('search', 'user', 'main');
    } else {
        $data['searchurl'] = xarModURL('search', 'user', 'main', array('by' => 'cat'));
    }
    $now = time();
    if (empty($startdate)) {
        $startdate = null;
        $data['startdate'] = 'N/A';
    } else {
        if (!preg_match('/[a-zA-Z]+/', $startdate)) {
            $startdate .= ' GMT';
        }
        $startdate = strtotime($startdate);
        // adjust for the user's timezone offset
        $startdate -= xarMLS_userOffset() * 3600;
        if ($startdate > $now && !$isadmin) {
            $startdate = $now;
        }
        $data['startdate'] = $startdate;
    }
    if (empty($enddate)) {
        $enddate = $now;
        $data['enddate'] = 'N/A';
    } else {
        if (!preg_match('/[a-zA-Z]+/', $enddate)) {
            $enddate .= ' GMT';
        }
        $enddate = strtotime($enddate);
        // adjust for the user's timezone offset
        $enddate -= xarMLS_userOffset() * 3600;
        if ($enddate > $now && !$isadmin) {
            $enddate = $now;
        }
        $data['enddate'] = $enddate;
    }
    if (!empty($q) || !empty($author) && isset($owner) || !empty($search) || !empty($ptid) || !empty($startdate) || $enddate != $now || !empty($catid)) {
        $getfields = array('id', 'title', 'start_date', 'pubtype_id', 'cids');
        // Return the relevance when using MySQL full-text search
        //if (!empty($search) && !empty($searchtype) && substr($searchtype,0,8) == 'fulltext') {
        //    $getfields[] = 'relevance';
        //}
        $count = 0;
        // TODO: allow combination of searches ?
        foreach ($ptids as $curptid) {
            $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'sort' => $sort, 'numitems' => $numitems, 'state' => $state, 'start_date' => $startdate, 'end_date' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q, 'fields' => $getfields));
            // TODO: re-use article output code from elsewhere (view / archive / admin)
            if (!empty($publications) && count($publications) > 0) {
                // 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
                        $catroots = xarModAPIFunc('publications', 'user', 'getrootcats', array('ptid' => $curptid));
                        $catroots = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid));
                    }
                    foreach ($catinfo as $cid => $info) {
                        $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']);
                        $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $curptid, '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['left_id'] && $info['left'] < $rootcat['right_id']) {
                                // only needed when sorting by root category id
                                $catinfo[$cid]['root'] = $rootcat['category_id'];
                                // only needed when sorting by root category order
                                $catinfo[$cid]['order'] = $rootidx;
                                break;
                            }
                            $rootidx++;
                        }
                    }
                }
                // needed for sort function below
                $GLOBALS['artsearchcatinfo'] = $catinfo;
                $items = array();
                foreach ($publications as $article) {
                    $count++;
                    $curptid = $article['pubtype_id'];
                    $link = xarModURL('publications', 'user', 'display', array('ptid' => $article['pubtype_id'], 'itemid' => $article['id']));
                    // publication date of article (if needed)
                    if (!empty($pubtypes[$curptid]['config']['startdate']['label']) && !empty($article['startdate'])) {
                        $date = xarLocaleFormatDate('%a, %d %B %Y %H:%M:%S %Z', $article['startdate']);
                        $startdate = $article['startdate'];
                    } else {
                        $date = '';
                        $startdate = 0;
                    }
                    if (empty($article['title'])) {
                        $article['title'] = xarML('(none)');
                    }
                    // categories this article belongs to
                    $categories = array();
                    if ($show_categories && !empty($article['cids']) && is_array($article['cids']) && count($article['cids']) > 0) {
                        $cidlist = $article['cids'];
                        // order cids by root category order
                        usort($cidlist, 'publications_search_sortbyorder');
                        // order cids by root category id
                        //usort($cidlist,'publications_search_sortbyroot');
                        // order cids by position in Celko tree
                        //usort($cidlist,'publications_search_sortbyleft');
                        $join = '';
                        foreach ($cidlist as $cid) {
                            $item = array();
                            if (!isset($catinfo[$cid])) {
                                // oops
                                continue;
                            }
                            $categories[] = array('cname' => $catinfo[$cid]['name'], 'clink' => $catinfo[$cid]['link'], 'cjoin' => $join);
                            if (empty($join)) {
                                $join = ' | ';
                            }
                        }
                    }
                    $items[] = array('title' => xarVarPrepHTMLDisplay($article['title']), 'link' => $link, 'date' => $date, 'startdate' => $startdate, 'relevance' => isset($article['relevance']) ? $article['relevance'] : null, 'categories' => $categories);
                }
                unset($publications);
                // Pager
                // TODO: make count depend on locale in the future
                sys::import('modules.base.class.pager');
                $pager = xarTplPager::getPager($startnum, xarModAPIFunc('publications', 'user', 'countitems', array('cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'state' => $state, 'startdate' => $startdate, 'enddate' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q)), xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'sort' => $sort, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'startnum' => '%%')), $numitems);
                if (strlen($pager) > 5) {
                    if (!isset($sort) || $sort == 'date') {
                        $othersort = 'title';
                    } else {
                        $othersort = null;
                    }
                    $sortlink = xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'sort' => $othersort));
                    if (!isset($othersort)) {
                        $othersort = 'date';
                    }
                    $pager .= '&#160;&#160;<a href="' . $sortlink . '">' . xarML('sort by') . ' ' . xarML($othersort) . '</a>';
                }
                $data['results'][] = array('description' => xarVarPrepForDisplay($pubtypes[$curptid]['description']), 'items' => $items, 'pager' => $pager);
            }
        }
        unset($catinfo);
        unset($items);
        unset($GLOBALS['artsearchcatinfo']);
        if ($count > 0) {
            // bail out, we have what we needed
            return xarTplModule('publications', 'user', 'search', $data);
        }
        $data['state'] = xarML('No pages found matching this search');
    }
    return xarTplModule('publications', 'user', 'search', $data);
}
Beispiel #23
0
/**
 * 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'];
    }
}
Beispiel #24
0
 public function encode(xarRequest $request)
 {
     if ($request->getType() == 'admin') {
         return parent::encode($request);
     }
     $params = $request->getFunctionArgs();
     $path = array();
     switch ($request->getFunction()) {
         case 'search':
             $path[] = 'search';
             $path = array_merge($path, $params);
             break;
         case 'view':
             $path[] = 'view';
             if (isset($params['ptid'])) {
                 if (xarModVars::get('publications', 'usetitleforurl')) {
                     // Get all publication types present
                     if (empty($this->pubtypes)) {
                         $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
                     }
                     // Match to the function token
                     foreach ($this->pubtypes as $id => $pubtype) {
                         if ($params['ptid'] == $id) {
                             $path[] = strtolower($pubtype['description']);
                             break;
                         }
                     }
                 } else {
                     $path[] = $params['ptid'];
                 }
             }
             unset($params['ptid']);
             break;
         case 'viewmap':
             $path[] = 'viewmap';
             $params = array();
             break;
         case 'display':
             if (isset($params['itemid'])) {
                 sys::import('xaraya.structures.query');
                 xarModLoad('publications');
                 $xartables = xarDB::getTables();
                 $q = new Query('SELECT', $xartables['publications']);
                 $q->eq('id', $params['itemid']);
                 $q->addfield('pubtype_id');
                 $q->addfield('name');
                 $q->addfield('id');
                 $q->run();
                 $result = $q->row();
                 if (xarModVars::get('publications', 'usetitleforurl')) {
                     // Get all publication types present
                     if (empty($this->pubtypes)) {
                         $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
                     }
                     if (!empty($result['pubtype_id'])) {
                         $path[] = strtolower($this->pubtypes[$result['pubtype_id']]['description']);
                     }
                     if (!empty($result['name'])) {
                         $path[] = strtolower($result['name']);
                     }
                 } else {
                     if (!empty($result['id'])) {
                         $path[] = $result['id'];
                     }
                 }
             }
             $params = array();
             break;
         case 'main':
             // We need a page ID to continue, for now.
             // TODO: allow this to be expanded to page names.
             if (empty($params['pid'])) {
                 return;
             }
             static $pages = NULL;
             // The components of the path.
             //    $get = $args;
             // Get the page tree that includes this page.
             // TODO: Do some kind of cacheing on a tree-by-tree basis to prevent
             // fetching this too many times. Every time any tree is fetched, anywhere
             // in this module, it should be added to the cache so it can be used again.
             // For now we are going to fetch all pages, without DD, to cut down on
             // the number of queries, although we are making an assumption that the
             // number of pages is not going to get too high.
             if (empty($pages)) {
                 // Fetch all pages, with no DD required.
                 $pages = xarMod::apiFunc('publications', 'user', 'getpages', array('dd_flag' => false, 'key' => 'pid'));
             }
             // Check that the pid is a valid page.
             if (!isset($pages[$params['pid']])) {
                 return;
             }
             $use_shortest_paths = xarModVars::get('publications', 'shortestpath');
             // Consume the pid from the get parameters.
             $pid = $params['pid'];
             unset($params['pid']);
             // 'Consume' the function now we know we have enough information.
             //                unset($params['func']);
             // Follow the tree up to the root.
             $pid_follow = $pid;
             while ($pages[$pid_follow]['parent_key'] != 0) {
                 // TODO: could do with an API to get all aliases for a given module in one go.
                 if (!empty($use_shortest_paths) && xarModGetAlias($pages[$pid_follow]['name']) == 'publications') {
                     break;
                 }
                 array_unshift($path, $pages[$pid_follow]['name']);
                 $pid_follow = $pages[$pid_follow]['parent_key'];
             }
             // Do the final path part.
             array_unshift($path, $pages[$pid_follow]['name']);
             // If the base path component is not the module alias, then add the
             // module name to the start of the path.
             if (xarModGetAlias($pages[$pid_follow]['name']) != 'publications') {
                 //                    array_unshift($path, 'publications');
             }
             // Now we have the basic path, we can check if there are any custom
             // URL handlers to handle the remainder of the GET parameters.
             // The handler is placed into the xarencodeapi API directory, and will
             // return two arrays: 'path' with path components and 'get' with
             // any unconsumed (or new) get parameters.
             if (!empty($pages[$pid]['encode_url'])) {
                 $extra = xarMod::apiFunc('publications', 'encode', $pages[$pid]['encode_url'], $get, false);
                 if (!empty($extra)) {
                     // The handler has supplied some further short URL path components.
                     if (!empty($extra['path'])) {
                         $path = array_merge($path, $extra['path']);
                     }
                     // Assume it has consumed some GET parameters too.
                     // Take what is left (i.e. unconsumed).
                     if (isset($extra['get']) && is_array($extra['get'])) {
                         $get = $extra['get'];
                     }
                 }
             }
             break;
         default:
             return;
             break;
     }
     // Encode the processed params
     $request->setFunction($this->getFunction($path));
     // Send the unprocessed params back
     $request->setFunctionArgs($params);
     return parent::encode($request);
 }
Beispiel #25
0
function publications_admin_updateconfig()
{
    // Confirm authorisation code
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Get parameters
    //A lot of these probably are bools, still might there be a need to change the template to return
    //'true' and 'false' to use those...
    if (!xarVarFetch('settings', 'array', $settings, array(), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usetitleforurl', 'int', $usetitleforurl, xarModVars::get('publications', 'usetitleforurl'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultstate', 'isset', $defaultstate, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultsort', 'isset', $defaultsort, 'date', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usealias', 'int', $usealias, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('multilanguage', 'int', $multilanguage, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1:10', $data['tab'], 'global', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) {
        return;
    }
    if ($data['tab'] == 'global') {
        if (!xarVarFetch('defaultpubtype', 'isset', $defaultpubtype, 1, XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('sortpubtypes', 'isset', $sortpubtypes, 'id', XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultlanguage', 'str:1:100', $defaultlanguage, xarModVars::get('publications', 'defaultlanguage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('debugmode', 'checkbox', $debugmode, xarModVars::get('publications', 'debugmode'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultfrontpage', 'str', $defaultfrontpage, xarModVars::get('publications', 'defaultfrontpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultbackpage', 'str', $defaultbackpage, xarModVars::get('publications', 'defaultbackpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        xarModVars::set('publications', 'defaultpubtype', $defaultpubtype);
        xarModVars::set('publications', 'sortpubtypes', $sortpubtypes);
        xarModVars::set('publications', 'defaultlanguage', $defaultlanguage);
        xarModVars::set('publications', 'debugmode', $debugmode);
        xarModVars::set('publications', 'usealias', $usealias);
        xarModVars::set('publications', 'usetitleforurl', $usetitleforurl);
        xarModVars::set('publications', 'defaultfrontpage', $defaultfrontpage);
        xarModVars::set('publications', 'defaultbackpage', $defaultbackpage);
        // Allow multilanguage only if the languages property is present
        sys::import('modules.dynamicdata.class.properties.registration');
        $types = PropertyRegistration::Retrieve();
        if (isset($types[30039])) {
            xarModVars::set('publications', 'multilanguage', $multilanguage);
        } else {
            xarModVars::set('publications', 'multilanguage', 0);
        }
        // Get the special pages.
        foreach (array('defaultpage', 'errorpage', 'notfoundpage', 'noprivspage') as $special_name) {
            unset($special_id);
            if (!xarVarFetch($special_name, 'id', $special_id, 0, XARVAR_NOT_REQUIRED)) {
                return;
            }
            xarModVars::set('publications', $special_name, $special_id);
        }
        if (xarDB::getType() == 'mysql') {
            if (!xarVarFetch('fulltext', 'isset', $fulltext, '', XARVAR_NOT_REQUIRED)) {
                return;
            }
            $oldval = xarModVars::get('publications', 'fulltextsearch');
            $index = 'i_' . xarDB::getPrefix() . '_publications_fulltext';
            if (empty($fulltext) && !empty($oldval)) {
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Drop fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} DROP INDEX {$index}";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', '');
            } elseif (!empty($fulltext) && empty($oldval)) {
                $searchfields = array('title', 'description', 'summary', 'body1', 'notes');
                //                $searchfields = explode(',',$fulltext);
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Add fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} ADD FULLTEXT {$index} (" . join(', ', $searchfields) . ")";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', join(',', $searchfields));
            }
        }
        // Module settings
        $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'publications'));
        $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls, user_menu_link', 'use_module_icons');
        $isvalid = $data['module_settings']->checkInput();
        if (!$isvalid) {
            return xarTplModule('base', 'admin', 'modifyconfig', $data);
        } else {
            $itemid = $data['module_settings']->updateItem();
        }
        // Pull the base category ids from the template and save them
        $picker = DataPropertyMaster::getProperty(array('name' => 'categorypicker'));
        $picker->checkInput('basecid');
    } elseif ($data['tab'] == 'pubtypes') {
        // Get the publication type for this display and save the settings to it
        $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $pubtypeobject->getItem(array('itemid' => $ptid));
        $configsettings = $pubtypeobject->properties['configuration']->getValue();
        $checkbox = DataPropertyMaster::getProperty(array('name' => 'checkbox'));
        $boxes = array('show_hitount', 'show_ratings', 'show_keywords', 'show_comments', 'show_prevnext', 'show_archives', 'show_publinks', 'show_pubcount', 'show_map', 'prevnextart', 'dot_transform', 'title_transform', 'show_categories', 'show_catcount', 'show_prevnext', 'allow_translations');
        foreach ($boxes as $box) {
            $isvalid = $checkbox->checkInput($box);
            if ($isvalid) {
                $settings[$box] = $checkbox->value;
            }
        }
        //        foreach ($configsettings as $key => $value)
        //            if (!isset($settings[$key])) $settings[$key] = 0;
        $isvalid = true;
        // Get the default access rules
        $access = DataPropertyMaster::getProperty(array('name' => 'access'));
        $validprop = $access->checkInput("access_add");
        $addaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_display");
        $displayaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_modify");
        $modifyaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_delete");
        $deleteaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $allaccess = array('add' => $addaccess, 'display' => $displayaccess, 'modify' => $modifyaccess, 'delete' => $deleteaccess);
        $pubtypeobject->properties['access']->setValue(serialize($allaccess));
        $pubtypeobject->properties['configuration']->setValue(serialize($settings));
        $pubtypeobject->updateItem(array('itemid' => $ptid));
        $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
        if ($usealias) {
            xarModSetAlias($pubtypes[$ptid]['name'], 'publications');
        } else {
            xarModDelAlias($pubtypes[$ptid]['name'], 'publications');
        }
    } elseif ($data['tab'] == 'redirects') {
        $redirects = DataPropertyMaster::getProperty(array('name' => 'array'));
        $redirects->display_column_definition['value'] = array(array("From", "To"), array(2, 2), array("", ""), array("", ""));
        $isvalid = $redirects->checkInput("redirects");
        xarModVars::set('publications', 'redirects', $redirects->value);
    }
    xarController::redirect(xarModURL('publications', 'admin', 'modifyconfig', array('ptid' => $ptid, 'tab' => $data['tab'])));
    return true;
}
Beispiel #26
0
/**
 * show monthly archive (Archives-like)
 */
function publications_user_archive($args)
{
    // Get parameters from user
    if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('sort', 'enum:d:t:1:2', $sort, 'd', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('month', 'str', $month, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Override if needed from argument array
    extract($args);
    // Get publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    // Check that the publication type is valid
    if (empty($ptid) || !isset($pubtypes[$ptid])) {
        $ptid = null;
    }
    if (empty($ptid)) {
        if (!xarSecurityCheck('ViewPublications', 0, 'Publication', 'All:All:All:All')) {
            return xarML('You have no permission to view these items');
        }
    } elseif (!xarSecurityCheck('ViewPublications', 0, 'Publication', $ptid . ':All:All:All')) {
        return xarML('You have no permission to view these items');
    }
    $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED);
    $seencid = array();
    $andcids = false;
    // 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;
            }
        }
    }
    if (isset($cids) && is_array($cids)) {
        foreach ($cids as $cid) {
            if (!empty($cid) && preg_match('/^_?[0-9]+$/', $cid)) {
                $seencid[$cid] = 1;
            }
        }
        $cids = array_keys($seencid);
        sort($cids, SORT_NUMERIC);
        if (empty($catid) && count($cids) > 1) {
            $andcids = true;
        }
    } else {
        $cids = null;
    }
    // QUESTION: work with user-dependent time settings or not someday ?
    // Set the start and end date for that month
    if (!empty($month) && preg_match('/^(\\d{4})-(\\d+)$/', $month, $matches)) {
        $startdate = gmmktime(0, 0, 0, $matches[2], 1, $matches[1]);
        // PHP allows month > 12 :-)
        $enddate = gmmktime(0, 0, 0, $matches[2] + 1, 1, $matches[1]);
        if ($enddate > time()) {
            $enddate = time();
        }
    } else {
        $startdate = '';
        $enddate = time();
        if (!empty($month) && $month != 'all') {
            $month = '';
        }
    }
    // Load API
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    if (!empty($ptid) && !empty($pubtypes[$ptid]['config']['pubdate']['label'])) {
        $showdate = 1;
    } else {
        $showdate = 0;
        foreach (array_keys($pubtypes) as $pubid) {
            if (!empty($pubtypes[$pubid]['config']['pubdate']['label'])) {
                $showdate = 1;
                break;
            }
        }
    }
    // Get monthly statistics
    $monthcount = xarModAPIFunc('publications', 'user', 'getmonthcount', array('ptid' => $ptid, 'state' => $state, 'enddate' => time()));
    if (empty($monthcount)) {
        $monthcount = array();
    }
    krsort($monthcount);
    reset($monthcount);
    $months = array();
    $total = 0;
    foreach ($monthcount as $thismonth => $count) {
        if ($thismonth == $month) {
            $mlink = '';
        } else {
            $mlink = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $thismonth));
        }
        $months[] = array('month' => $thismonth, 'mcount' => $count, 'mlink' => $mlink);
        $total += $count;
    }
    if (empty($ptid)) {
        $thismonth = xarML('All Publications');
    } else {
        $thismonth = xarML('All') . ' ' . $pubtypes[$ptid]['description'];
    }
    if ($month == 'all') {
        $mlink = '';
    } else {
        $mlink = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => 'all'));
    }
    $months[] = array('month' => $thismonth, 'mcount' => $total, 'mlink' => $mlink);
    // Load API
    if (!xarModAPILoad('categories', 'user')) {
        return;
    }
    // Get the list of root categories for this publication type
    if (!empty($ptid)) {
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
    } else {
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => 0));
    }
    $catlist = array();
    $catinfo = array();
    $catsel = array();
    if (!empty($rootcats)) {
        // TODO: do this in categories API ?
        $count = 1;
        foreach ($rootcats as $cid) {
            if (empty($cid)) {
                continue;
            }
            // save the name and root category for each child
            $cats = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid['category_id'], 'return_itself' => true, 'getchildren' => true));
            foreach ($cats as $info) {
                $item = array();
                $item['name'] = $info['name'];
                $item['root'] = $cid['category_id'];
                $catinfo[$info['cid']] = $item;
            }
            // don't allow sorting by category when viewing all publications
            //if ($sort == $count || $month == 'all') {
            if ($sort == $count) {
                $link = '';
            } else {
                $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => $count));
            }
            // catch more faulty categories assignments
            if (isset($catinfo[$cid['category_id']])) {
                $catlist[] = array('cid' => $cid['category_id'], 'name' => $catinfo[$cid['category_id']]['name'], 'link' => $link);
                $catsel[] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $cid['category_id'], 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 0));
                $count++;
            }
        }
    }
    // Get publications
    if ($month == 'all' || $startdate && $enddate) {
        $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => isset($ptid) ? $ptid : null, 'startdate' => $startdate, 'enddate' => $enddate, 'state' => $state, 'cids' => $cids, 'andcids' => $andcids, 'fields' => array('id', 'title', 'start_date', 'pubtype_id', 'cids')));
        if (!is_array($publications)) {
            $msg = xarML('Failed to retrieve publications in #(3)_#(1)_#(2).php', 'user', 'getall', 'publications');
            throw new DataNotFoundException(null, $msg);
        }
    } else {
        $publications = array();
    }
    // TODO: add print / recommend_us link for each article ?
    // TODO: add view count to table/query/template someday ?
    foreach ($publications as $key => $article) {
        $publications[$key]['link'] = xarModURL('publications', 'user', 'display', array('ptid' => isset($ptid) ? $publications[$key]['pubtype_id'] : null, 'id' => $publications[$key]['id']));
        if (empty($publications[$key]['title'])) {
            $publications[$key]['title'] = xarML('(none)');
        }
        /* TODO: move date formatting to template, delete this code after testing
                if ($showdate && !empty($publications[$key]['pubdate'])) {
                    $publications[$key]['date'] = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S",
                                                       $publications[$key]['pubdate']);
                } else {
                    $publications[$key]['date'] = '';
                }
        */
        // TODO: find some better way to do this...
        $list = array();
        // get all the categories for that article and put them under the
        // right root category
        if (!isset($publications[$key]['cids'])) {
            $publications[$key]['cids'] = array();
        }
        foreach ($publications[$key]['cids'] as $cid) {
            // skip unknown categories (e.g. when not under root categories)
            if (!isset($catinfo[$cid])) {
                continue;
            }
            if (!isset($list[$catinfo[$cid]['root']])) {
                $list[$catinfo[$cid]['root']] = array();
            }
            array_push($list[$catinfo[$cid]['root']], $cid);
        }
        // fill in the column corresponding to each root category
        $publications[$key]['cats'] = array();
        foreach ($catlist as $cat) {
            if (isset($list[$cat['cid']])) {
                $descr = '';
                // TODO: add links to category someday ?
                foreach ($list[$cat['cid']] as $cid) {
                    if (!empty($descr)) {
                        $descr .= '<br />';
                    }
                    $descr .= $catinfo[$cid]['name'];
                }
                $publications[$key]['cats'][] = array('list' => $descr);
            } else {
                $publications[$key]['cats'][] = array('list' => '-');
            }
        }
    }
    // sort publications as requested
    if ($sort == 2 && count($catlist) > 1) {
        usort($publications, 'publications_archive_sortbycat10');
    } elseif ($sort == 1) {
        if (count($catlist) > 1) {
            usort($publications, 'publications_archive_sortbycat01');
        } elseif (count($catlist) > 0) {
            usort($publications, 'publications_archive_sortbycat0');
        }
    } elseif ($sort == 't') {
        usort($publications, 'publications_archive_sortbytitle');
    } else {
        $sort = 'd';
        // default sort by date is already done in getall() function
    }
    // add title header
    if ($sort == 't') {
        $link = '';
    } else {
        $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => 't'));
    }
    $catlist[] = array('cid' => 0, 'name' => xarML('Title'), 'link' => $link);
    $catsel[] = '<input type="submit" value="' . xarML('Filter') . '" />';
    if ($showdate) {
        // add date header
        if ($sort == 'd') {
            $link = '';
        } else {
            $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month));
        }
        $catlist[] = array('cid' => 0, 'name' => xarML('Date'), 'link' => $link);
        $catsel[] = '&#160;';
    }
    // Save some variables to (temporary) cache for use in blocks etc.
    xarVarSetCached('Blocks.publications', 'ptid', $ptid);
    if (!empty($cids)) {
        xarVarSetCached('Blocks.publications', 'cids', $cids);
    }
    //if ($shownavigation) {
    xarVarSetCached('Blocks.categories', 'module', 'publications');
    xarVarSetCached('Blocks.categories', 'itemtype', $ptid);
    if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) {
        xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']);
        xarTplSetPageTitle(xarML('Archive'), $pubtypes[$ptid]['description']);
    } else {
        xarTplSetPageTitle(xarML('Archive'));
    }
    //}
    if (!empty($ptid)) {
        $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid));
    } else {
        $string = xarModVars::get('publications', 'settings');
        if (!empty($string)) {
            $settings = unserialize($string);
        }
    }
    if (!isset($show_publinks)) {
        if (!empty($settings['show_publinks'])) {
            $show_publinks = 1;
        } else {
            $show_publinks = 0;
        }
    }
    // show the number of publications for each publication type
    if (!isset($show_pubcount)) {
        if (!isset($settings['show_pubcount']) || !empty($settings['show_pubcount'])) {
            $show_pubcount = 1;
            // default yes
        } else {
            $show_pubcount = 0;
        }
    }
    //    $show_catcount = 0; // unused here
    // return template out
    $data = array('months' => $months, 'publications' => $publications, 'catlist' => $catlist, 'catsel' => $catsel, 'ptid' => $ptid, 'month' => $month, 'curlink' => xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => $sort)), 'showdate' => $showdate, 'show_publinks' => $show_publinks, 'publabel' => xarML('Publication'), 'publinks' => xarModAPIFunc('publications', 'user', 'getpublinks', array('ptid' => $ptid, 'state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'count' => $show_pubcount, 'func' => 'archive')), 'maplabel' => xarML('View Publication Map'), 'maplink' => xarModURL('publications', 'user', 'viewmap', array('ptid' => $ptid)), 'viewlabel' => empty($ptid) ? xarML('Back to Publications') : xarML('Back to') . ' ' . $pubtypes[$ptid]['description'], 'viewlink' => xarModURL('publications', 'user', 'view', array('ptid' => $ptid)));
    if (!empty($ptid)) {
        $template = $pubtypes[$ptid]['name'];
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    return xarTplModule('publications', 'user', 'archive', $data, $template);
}
Beispiel #27
0
 public function display(array $data = array())
 {
     $data = $this->getContent();
     // see if we're currently displaying an article
     if (xarVarIsCached('Blocks.publications', 'id')) {
         $curid = xarVarGetCached('Blocks.publications', 'id');
     } else {
         $curid = -1;
     }
     if (!empty($data['dynamictitle'])) {
         if ($data['toptype'] == 'rating') {
             $data['title'] = xarML('Top Rated');
         } elseif ($data['toptype'] == 'hits') {
             $data['title'] = xarML('Top');
         } else {
             $data['title'] = xarML('Latest');
         }
     }
     if (!empty($data['nocatlimit'])) {
         // don't limit by category
         $cid = 0;
         $cidsarray = array();
     } else {
         if (!empty($data['catfilter'])) {
             // use admin defined category
             $cidsarray = array($data['catfilter']);
             $cid = $data['catfilter'];
         } else {
             // use the current category
             // Jonn: this currently only works with one category at a time
             // it could be reworked to support multiple cids
             if (xarVarIsCached('Blocks.publications', 'cids')) {
                 $curcids = xarVarGetCached('Blocks.publications', 'cids');
                 if (!empty($curcids)) {
                     if ($curid == -1) {
                         //$cid = $curcids[0]['name'];
                         $cid = $curcids[0];
                         $cidsarray = array($curcids[0]);
                     } else {
                         $cid = $curcids[0];
                         $cidsarray = array($curcids[0]);
                     }
                 } else {
                     $cid = 0;
                     $cidsarray = array();
                 }
             } else {
                 // pull from all categories
                 $cid = 0;
                 $cidsarray = array();
             }
         }
         //echo $includechildren;
         if (!empty($data['includechildren']) && !empty($cidsarray[0]) && !strstr($cidsarray[0], '_')) {
             $cidsarray[0] = '_' . $cidsarray[0];
         }
         if (!empty($cid)) {
             // if we're viewing all items below a certain category, i.e. catid = _NN
             $cid = str_replace('_', '', $cid);
             $thiscategory = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid, 'return_itself' => 'return_itself'));
         }
         if (!empty($cidsarray) && isset($thiscategory[0]['name']) && !empty($data['dynamictitle'])) {
             $data['title'] .= ' ' . $thiscategory[0]['name'];
         }
     }
     // Get publication types
     // MarieA - moved to always get pubtypes.
     $publication_types = xarModAPIFunc('publications', 'user', 'get_pubtypes');
     if (!empty($data['nopublimit'])) {
         //don't limit by publication type
         $ptid = 0;
         if (!empty($data['dynamictitle'])) {
             $data['title'] .= ' ' . xarML('Content');
         }
     } else {
         // MikeC: Check to see if admin has specified that only a specific
         // Publication Type should be displayed.  If not, then default to original TopItems configuration.
         if ($data['pubtype_id'] == 0) {
             if (xarVarIsCached('Blocks.publications', 'ptid')) {
                 $ptid = xarVarGetCached('Blocks.publications', 'ptid');
             }
             if (empty($ptid)) {
                 // default publication type
                 $ptid = xarModVars::get('publications', 'defaultpubtype');
             }
         } else {
             // MikeC: Admin Specified a publication type, use it.
             $ptid = $data['pubtype_id'];
         }
         if (!empty($data['dynamictitle'])) {
             if (!empty($ptid) && isset($publication_types[$ptid]['description'])) {
                 $data['title'] .= ' ' . xarVarPrepForDisplay($publication_types[$ptid]['description']);
             } else {
                 $data['title'] .= ' ' . xarML('Content');
             }
         }
     }
     // frontpage or approved state
     if (empty($data['pubstate'])) {
         $statearray = array(2, 3);
     } elseif (!is_array($data['pubstate'])) {
         $statearray = preg_split('/,/', $data['pubstate']);
     } else {
         $statearray = $data['pubstate'];
     }
     // get cids for security check in getall
     $fields = array('id', 'title', 'pubtype_id', 'cids');
     if ($data['toptype'] == 'rating' && xarModIsHooked('ratings', 'publications', $ptid)) {
         array_push($fields, 'rating');
         $sort = 'rating';
     } elseif ($data['toptype'] == 'hits' && xarModIsHooked('hitcount', 'publications', $ptid)) {
         array_push($fields, 'counter');
         $sort = 'hits';
     } else {
         array_push($fields, 'create_date');
         $sort = 'date';
     }
     if (!empty($data['showsummary'])) {
         array_push($fields, 'summary');
     }
     if (!empty($data['showdynamic']) && xarModIsHooked('dynamicdata', 'publications', $ptid)) {
         array_push($fields, 'dynamicdata');
     }
     $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => $ptid, 'cids' => $cidsarray, 'andcids' => 'false', 'state' => $statearray, 'create_date' => time(), 'fields' => $fields, 'sort' => $sort, 'numitems' => $data['numitems']));
     if (!isset($publications) || !is_array($publications) || count($publications) == 0) {
         return;
     }
     $items = array();
     foreach ($publications as $article) {
         $article['title'] = xarVarPrepHTMLDisplay($article['title']);
         if ($article['id'] != $curid) {
             // Use the filtered category if set, and not including children
             $article['link'] = xarModURL('publications', 'user', 'display', array('itemid' => $article['id'], 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL));
         } else {
             $article['link'] = '';
         }
         if (!empty($data['showvalue'])) {
             if ($data['toptype'] == 'rating') {
                 if (!empty($article['rating'])) {
                     $article['value'] = intval($article['rating']);
                 } else {
                     $article['value'] = 0;
                 }
             } elseif ($data['toptype'] == 'hits') {
                 if (!empty($article['counter'])) {
                     $article['value'] = $article['counter'];
                 } else {
                     $article['value'] = 0;
                 }
             } else {
                 // TODO: make user-dependent
                 if (!empty($article['create_date'])) {
                     //$article['value'] = strftime("%Y-%m-%d", $article['create_date']);
                     $article['value'] = xarLocaleGetFormattedDate('short', $article['create_date']);
                 } else {
                     $article['value'] = 0;
                 }
             }
         } else {
             $article['value'] = 0;
         }
         // MikeC: Bring the summary field back as $desc
         if (!empty($data['showsummary'])) {
             $article['summary'] = xarVarPrepHTMLDisplay($article['summary']);
             $article['transform'] = array('summary', 'title');
             $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications');
         } else {
             $article['summary'] = '';
         }
         // MarieA: Bring the pubtype description back as $descr
         if (!empty($data['nopublimit'])) {
             $article['pubtypedescr'] = $publication_types[$article['pubtype_id']]['description'];
             //jojodee: while we are here bring the pubtype name back as well
             $article['pubtypename'] = $publication_types[$article['pubtype_id']]['name'];
         }
         // this will also pass any dynamic data fields (if any)
         $items[] = $article;
     }
     $data['items'] = $items;
     if (!empty($data['dynamictitle'])) {
         $this->setTitle($data['title']);
     }
     return $data;
 }
function mailer_admin_modifyconfig()
{
    // Security Check
    if (!xarSecurityCheck('AdminMailer')) {
        return;
    }
    if (!xarVarFetch('phase', 'str:1:100', $phase, 'modify', XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1:100', $data['tab'], 'general', XARVAR_NOT_REQUIRED)) {
        return;
    }
    switch (strtolower($phase)) {
        case 'modify':
        default:
            switch ($data['tab']) {
                case 'general':
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            break;
        case 'update':
            // Confirm authorisation code
            if (!xarSecConfirmAuthKey()) {
                return;
            }
            switch ($data['tab']) {
                case 'general':
                    if (!xarVarFetch('itemsperpage', 'int', $itemsperpage, xarModVars::get('mailer', 'itemsperpage'), XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) {
                        return;
                    }
                    if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    if (!xarVarFetch('modulealias', 'checkbox', $useModuleAlias, xarModVars::get('mailer', 'useModuleAlias'), XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    if (!xarVarFetch('aliasname', 'str', $aliasname, xarModVars::get('mailer', 'aliasname'), XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    xarModVars::set('mailer', 'itemsperpage', $itemsperpage);
                    xarModVars::set('mailer', 'SupportShortURLs', $shorturls);
                    xarModVars::set('mailer', 'useModuleAlias', $useModuleAlias);
                    xarModVars::set('mailer', 'aliasname', $aliasname);
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            xarController::redirect(xarModURL('mailer', 'admin', 'modifyconfig', array('tab' => $data['tab'])));
            // Return
            return true;
            break;
    }
    $data['authid'] = xarSecGenAuthKey();
    return $data;
}
Beispiel #29
0
/**
 * view article map
 */
function publications_user_viewmap($args)
{
    // Get parameters
    if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('by', 'enum:pub:cat:grid', $by, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('go', 'str', $go, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Override if needed from argument array
    extract($args);
    $default = xarModVars::get('publications', 'defaultpubtype');
    if (empty($by)) {
        if (empty($default) && empty($ptid)) {
            $by = 'cat';
        } else {
            $by = 'pub';
        }
    }
    // 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;
        } else {
            $cids = explode('-', $catid);
            $andcids = false;
        }
    }
    $seencid = array();
    if (isset($cids) && is_array($cids)) {
        foreach ($cids as $cid) {
            // make sure cids are numeric
            if (!empty($cid) && is_numeric($cid)) {
                $seencid[$cid] = 1;
            }
        }
        $cids = array_keys($seencid);
        sort($cids, SORT_NUMERIC);
    }
    // Get publication types
    sys::import('modules.dynamicdata.class.objects.master');
    $object = DataObjectMaster::getObjectList(array('name' => 'publications_types'));
    $data['pubtypes'] = $object->getItems();
    // redirect to filtered view
    if (!empty($go) && (!empty($ptid) || $by == 'cat')) {
        if (is_array($cids) && count($cids) > 0) {
            $catid = join('+', $cids);
        } else {
            $catid = NULL;
        }
        $url = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $catid));
        xarController::redirect($url);
        return;
    }
    $data['catfilter'] = array();
    $data['cattree'] = array();
    $data['catgrid'] = array();
    $dump = '';
    $publinks = array();
    if ($by == 'cat') {
        $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'cat'));
        // TODO: re-evaluate this after user feedback...
        // *trick* Use the 'default' categories here, instead of all rootcats
        $basecats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications'));
        $catlist = array();
        foreach ($basecats as $basecat) {
            $catlist[$basecat['category_id']] = 1;
        }
        $data['basecids'] = array_keys($catlist);
        // create the category tree for each root category
        // TODO: make sure permissions are taken into account here !
        foreach ($catlist as $cid => $val) {
            if (empty($val)) {
                continue;
            }
            $data['cattree'][$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_APPROVED, PUBLICATIONS_STATE_FRONTPAGE), 'cid' => $cid, 'ptid' => null, 'showcid' => true));
        }
    } elseif ($by == 'grid') {
        $data['catgrid'][0] = array();
        $data['catgrid'][0][0] = '';
        // Get the base categories
        if (!empty($ptid)) {
            $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
        } else {
            $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => 0));
            $ptid = null;
        }
        if (count($rootcats) != 2) {
            $data['catgrid'][0][0] = xarML('You need 2 base categories in order to use this grid view');
        } else {
            $catlist = array();
            if (!empty($rootcats) && is_array($rootcats)) {
                foreach ($rootcats as $cid) {
                    $catlist[$catid['category_id']] = 1;
                }
            }
            $cattree = array();
            // Get the category tree for each base category
            foreach ($catlist as $cid => $val) {
                if (empty($val)) {
                    continue;
                }
                $cattree[$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $ptid, 'showcid' => true));
            }
            // Find out which category tree is the shortest
            if (count($cattree[$rootcats[0]]) > count($cattree[$rootcats[1]])) {
                $rowcat = $rootcats[0];
                $colcat = $rootcats[1];
            } else {
                $rowcat = $rootcats[1];
                $colcat = $rootcats[0];
            }
            // Fill in the column headers
            $row = 0;
            $col = 1;
            $colcid = array();
            foreach ($cattree[$colcat] as $info) {
                $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>';
                $colcid[$info['id']] = $col;
                $col++;
            }
            $maxcol = $col;
            // Fill in the row headers
            $row = 1;
            $col = 0;
            $data['catgrid'][$row] = array();
            $rowcid = array();
            foreach ($cattree[$rowcat] as $info) {
                $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>';
                $rowcid[$info['id']] = $row;
                $row++;
            }
            $maxrow = $row;
            // Initialise the rest of the array
            for ($row = 1; $row < $maxrow; $row++) {
                if (!isset($data['catgrid'][$row])) {
                    $data['catgrid'][$row] = array();
                }
                for ($col = 1; $col < $maxcol; $col++) {
                    $data['catgrid'][$row][$col] = '';
                }
            }
            // Get the counts for all groups of (N) categories
            $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'ptid' => $ptid, 'groupcids' => 2, 'reverse' => 1));
            if (!empty($ptid)) {
                $what = $ptid;
            } else {
                $what = 'total';
            }
            // Fill in the count values
            foreach ($pubcatcount as $cids => $counts) {
                list($ca, $cb) = explode('+', $cids);
                if (isset($rowcid[$ca]) && isset($colcid[$cb])) {
                    $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $ca . '+' . $cb));
                    $data['catgrid'][$rowcid[$ca]][$colcid[$cb]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>';
                }
                if (isset($rowcid[$cb]) && isset($colcid[$ca])) {
                    $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $cb . '+' . $ca));
                    $data['catgrid'][$rowcid[$cb]][$colcid[$ca]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>';
                }
            }
        }
        if (!empty($ptid)) {
            $descr = $data['pubtypes'][$ptid]['description'];
        }
    } else {
        $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'pub'));
        // get the links and counts for all publication types
        $publinks = xarModAPIFunc('publications', 'user', 'getpublinks', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'all' => 1));
        // build the list of root categories for all publication types
        // and save results in publinks as well
        $catlist = array();
        for ($i = 0; $i < count($publinks); $i++) {
            $pubid = $publinks[$i]['pubid'];
            $cidstring = xarModVars::get('publications', 'mastercids.' . $pubid);
            if (!empty($cidstring)) {
                $rootcats = explode(';', $cidstring);
                foreach ($rootcats as $cid) {
                    $catlist[$cid] = 1;
                }
                $publinks[$i]['rootcats'] = $rootcats;
            } else {
                $publinks[$i]['rootcats'] = array();
            }
        }
        // for all publication types
        for ($i = 0; $i < count($publinks); $i++) {
            $publinks[$i]['cats'] = array();
            $pubid = $publinks[$i]['pubid'];
            // for each root category of this publication type
            foreach ($publinks[$i]['rootcats'] as $cid) {
                // add the category tree to the list of categories to show
                $childcats = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $pubid, 'showcid' => true));
                $publinks[$i]['cats'][] = $childcats;
            }
        }
        $array = array();
        if (empty($ptid)) {
            $ptid = $default;
        }
        if (!empty($ptid)) {
            for ($i = 0; $i < count($publinks); $i++) {
                if ($ptid == $publinks[$i]['pubid']) {
                    $array = $publinks[$i]['rootcats'];
                }
            }
        }
        foreach ($publinks as $pub) {
            if ($pub['pubid'] == $ptid) {
                $descr = $pub['pubtitle'];
            }
        }
    }
    if (empty($descr)) {
        $descr = xarML('Publications');
        $data['descr'] = '';
    } else {
        $data['descr'] = $descr;
    }
    // Save some variables to (temporary) cache for use in blocks etc.
    xarVarSetCached('Blocks.publications', 'ptid', $ptid);
    //if ($shownavigation) {
    xarVarSetCached('Blocks.categories', 'module', 'publications');
    xarVarSetCached('Blocks.categories', 'itemtype', $ptid);
    if (!empty($descr)) {
        xarVarSetCached('Blocks.categories', 'title', $descr);
        xarTplSetPageTitle(xarML('Map'), xarVarPrepForDisplay($descr));
    }
    //}
    if (empty($ptid)) {
        $ptid = null;
    }
    $data['publinks'] = $publinks;
    $data['ptid'] = $ptid;
    $data['viewlabel'] = xarML('Back to') . ' ' . $descr;
    $data['viewlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid));
    $data['archivelabel'] = xarML('View Archives');
    $data['archivelink'] = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid));
    $data['dump'] = $dump;
    if (count($data['catfilter']) == 2) {
    }
    if (!empty($ptid)) {
        $object = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $object->getItem(array('itemid' => $ptid));
        $template = $object->properties['template']->value;
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    // Pass the type of map to the template, so we can decide what links to show
    $data['by'] = $by;
    return xarTplModule('publications', 'user', 'viewmap', $data, $template);
}
Beispiel #30
0
function calendar_user_day()
{
    $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo');
    $DayEvents = new Calendar_Day($data['cal_year'], $data['cal_month'], $data['cal_day'], CALENDAR_FIRST_DAY_OF_WEEK);
    $args = array('day' => &$Day);
    $day_endts = $DayEvents->getTimestamp() + xarModVars::get('calendar', 'day_end') + 3600;
    //        $events = xarMod::apiFunc('icalendar','user','getevents',$args);
    // get all the events. need to improve this query
    $xartable = xarDB::getTables();
    $q = new Query('SELECT', $xartable['calendar_event']);
    //        $q->qecho();
    if (!$q->run()) {
        return;
    }
    $events = $q->output();
    // Do some calculations to complete the entries' info
    $slots = array();
    // Loop through the events
    $eventcount = count($events);
    for ($j = 0; $j < $eventcount; $j++) {
        // make sure events don't go past the end of the day
        $events[$j]['end_time'] = min($events[$j]['end_time'], $day_endts);
        $placed = false;
        $slotcount = count($slots);
        for ($i = 0; $i < $slotcount; $i++) {
            if ($events[$j]['start_time'] >= $slots[$i][1]) {
                foreach ($slots as $slot) {
                    $events[$slot[0]]['neighbors'] = $slotcount;
                }
                $thisslot = $i;
                $slots = array(0 => array($j, $events[$j]['end_time']));
                $placed = true;
                break;
            }
        }
        if (!$placed) {
            $thisslot = $slotcount;
            $slots[] = array($j, $events[$j]['end_time']);
        }
        $events[$j]['place'] = $thisslot;
    }
    foreach ($slots as $slot) {
        $events[$slot[0]]['neighbors'] = $slotcount;
    }
    //foreach($events as $event) {var_dump($event);echo "<br />";}
    /*
    $selection = array();
    foreach ( $entries as $entry ) {
        $Hour = new Calendar_Hour(2000,1,1,1);
        $Hour->setTimeStamp($entry['start_time']);
    
        // Create the decorator, passing it the Hour
        $event = new Event($Hour);
    
        // Attach the payload
        $event->setEntry($entry);
    
        // Add the decorator to the selection
        $selection[] = $event;
    }
    */
    $DayDecorator = new DayEvent_Decorator($DayEvents);
    $DayDecorator->build($events);
    $data['Day'] =& $DayDecorator;
    $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK;
    return $data;
}