Example #1
0
 /**
  * Create instance
  */
 function factory($driver = null, $params = array())
 {
     if ($driver === null) {
         $driver = $GLOBALS['conf']['report_content']['driver'];
     }
     if (empty($params)) {
         $params = $GLOBALS['conf']['report_content'];
     }
     $class_name = 'Ansel_Report_' . $driver;
     if (!class_exists($class_name)) {
         return PEAR::RaiseError(_("Report driver does not exist."));
     }
     $report = new $class_name($params);
     return $report;
 }
 function get_usrloc($uid, &$errors)
 {
     global $config, $sess;
     $contacts = array();
     if ($config->use_rpc) {
         /* 
          * get contacts useing xml-rpc and store them into array $contacts 
          */
         if (!$this->connect_to_xml_rpc(null, $errors)) {
             return false;
         }
         $params = array(new XML_RPC_Value($config->ul_table, 'string'), new XML_RPC_Value($uid, 'string'));
         $msg = new XML_RPC_Message('usrloc.show_contacts', $params);
         $res = $this->rpc->send($msg);
         if ($this->rpc_is_error($res)) {
             /* if usrloc of user is empty */
             if ($res->getCode() == "404") {
                 return array();
             }
             log_errors($res, $errors);
             return false;
         }
         $val = $res->value();
         if ($val->kindOf() != "array") {
             log_errors(PEAR::RaiseError("sorry invalid output from SER"), $errors);
             return false;
         }
         $size = $val->arraySize();
         for ($i = 0; $i < $size; $i++) {
             $contact = $val->arrayMem($i);
             if ($contact->kindOf() != "struct") {
                 log_errors(PEAR::RaiseError("sorry invalid output from SER"), $errors);
                 return false;
             }
             $contacts[$i] = new stdClass();
             $contacts[$i]->contact = $contact->structMem("contact");
             $contacts[$i]->q = $contact->structMem("q");
             $contacts[$i]->expires = $contact->structMem("expires");
             $contacts[$i]->contact = $contacts[$i]->contact->scalarval();
             $contacts[$i]->q = $contacts[$i]->q->scalarval();
             $contacts[$i]->expires = $contacts[$i]->expires->scalarval();
         }
     } else {
         /* 
          * get contacts useing xml-rpc and store them into array $contacts 
          */
         $fifo_cmd = ":usrloc.show_contacts:" . $config->reply_fifo_filename . "\n" . $config->ul_table . "\n" . $uid . "\n" . "\n";
         $fifo_out = write2fifo($fifo_cmd, $err, $status);
         if ($err) {
             $errors = array_merge($errors, $err);
             return false;
         }
         if (substr($status, 0, 1) != "2" and substr($status, 0, 3) != "404") {
             $errors[] = $status;
             return false;
         }
         /*
          *	Example of FIFO output:
          *
          *	expires:834277,q:1.000000,contact:sip\okk@kk.cz
          *	expires:34303,q:1.000000,contact:sip\osdaf@dfdf.cd
          *	expires:3335,q:0.000000,contact:sip\odsa@iptel.org
          *	expires:3191,q:0.000000,contact:sip\osdaf@iptedfl.org
          */
         $out_arr = explode("\n", $fifo_out);
         $i = 0;
         foreach ($out_arr as $val) {
             if (!ereg("^[[:space:]]*\$", $val)) {
                 //					if (ereg("<([^>]*)>;q=([0-9.]*);expires=(-?[0-9]*)", $val, $regs)){
                 if (ereg('expires:(-?[0-9]*),q:([0-9.]*),contact:(.*)$', $val, $regs)) {
                     $contacts[$i] = new stdClass();
                     $contacts[$i]->contact = str_replace('\\o', ':', $regs[3]);
                     $contacts[$i]->q = $regs[2];
                     $contacts[$i]->expires = $regs[1];
                     $i++;
                 } else {
                     log_errors(PEAR::RaiseError("sorry invalid output from fifo"), $errors);
                     return false;
                 }
             }
         }
     }
     /* 
      * format array of contact for output
      */
     $i = 0;
     $out = array();
     foreach ($contacts as $val) {
         $exp_timestamp = time() + $val->expires;
         $expires = date('Y-m-d H:i', $exp_timestamp);
         if (substr($expires, 0, 10) == date('Y-m-d')) {
             $date = substr($expires, 11, 5);
         } else {
             $date = substr($expires, 0, 10);
         }
         // 567640000 means 18 years
         if ((int) $val->expires < 0 or (int) $val->expires > 567640000) {
             $date = "never";
             $exp_timestamp = -1;
         }
         $out[$i]['uri'] = $val->contact;
         $out[$i]['q'] = $val->q;
         $out[$i]['expires'] = $date;
         $out[$i]['exp_timestamp'] = $exp_timestamp;
         $out[$i]['geo_loc'] = $this->get_location($val->contact, $errors);
         $i++;
     }
     return $out;
 }
/**
 *  Function load additional language file
 *  
 *  This function may be used for example to loading modules purpose 
 *  
 *  @param  string  $ldir   path to directory which is scanned for language files
 *  @return bool            TRUE on success, FALSE when file is not found
 */
function load_another_lang($ldir){
    global $_SERWEB, $reference_language, $available_languages, $lang_str, $lang_set;

    $ldir = $_SERWEB["langdir"].$ldir."/";

    $primary_lang_file   = $ldir.$available_languages[$_SESSION['lang']][1].".php";
    $secondary_lang_file = $ldir.$available_languages[$reference_language][1].".php";
    
    if (file_exists($primary_lang_file)){
        require_once($primary_lang_file);
    }
    elseif(file_exists($secondary_lang_file)){
        require_once($secondary_lang_file);
    }
    else{
        ErrorHandler::log_errors(PEAR::RaiseError("Can't find requested language file", 
                                 NULL, NULL, NULL, 
                                 "Nor requested(".$primary_lang_file.") neither default(".$secondary_lang_file.") language file not exists"));
        
        return false;
    }

    return true;
}
Example #4
0
if (isset($_REQUEST['followup'])) {
    processFollowup();
}
// Process Solr shard settings
processShards();
// Call Action
if (is_readable("services/{$module}/{$action}.php")) {
    include_once "services/{$module}/{$action}.php";
    if (class_exists($action)) {
        $service = new $action();
        $service->launch();
    } else {
        PEAR::raiseError(new PEAR_Error('Unknown Action'));
    }
} else {
    PEAR::RaiseError(new PEAR_Error('Cannot Load Action'));
}
/**
 * Handle processing and/or redirection for user followup actions.
 *
 * @return void
 */
function processFollowup()
{
    global $configArray;
    // The MyResearch/Login action may assign a value to followup.  In the case of
    // a SaveSearch action, we need to redirect after a successful login.  This
    // behavior is rather confusing -- we should consider achieving the same effect
    // in a more straightforward way.
    switch ($_REQUEST['followup']) {
        case 'SaveSearch':
 function create_html_form(&$errors)
 {
     global $data, $config;
     parent::create_html_form($errors);
     $attr_types =& Attr_types::singleton();
     //get list of attributes
     if (false === ($this->attr_types =& $attr_types->get_attr_types())) {
         return false;
     }
     switch ($this->opt['attrs_kind']) {
         case "uri":
             // get uri_attrs
             $this->uri_attrs =& Uri_Attrs::singleton($this->uri_scheme, $this->uri_uname, $this->uri_did);
             if (false === ($uri_attrs = $this->uri_attrs->get_attributes())) {
                 return false;
             }
         case "user":
             // get user_attrs
             $this->user_attrs =& User_Attrs::singleton($this->uid);
             if (false === ($user_attrs = $this->user_attrs->get_attributes())) {
                 return false;
             }
         case "domain":
             // get domain_attrs
             $this->domain_attrs =& Domain_Attrs::singleton($this->did);
             if (false === ($domain_attrs = $this->domain_attrs->get_attributes())) {
                 return false;
             }
         case "global":
             // get global_attrs
             $this->global_attrs =& Global_Attrs::singleton();
             if (false === ($global_attrs = $this->global_attrs->get_attributes())) {
                 return false;
             }
     }
     $this->attr_values = array();
     foreach ($this->attr_types as $k => $v) {
         if ($this->opt['attrs_kind'] == 'uri' and !$this->attr_types[$k]->is_for_URIs()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'user' and !$this->attr_types[$k]->is_for_users()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'domain' and !$this->attr_types[$k]->is_for_domains()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'global' and !$this->attr_types[$k]->is_for_globals()) {
             continue;
         }
         switch ($this->opt['attrs_kind']) {
             case "uri":
                 if (isset($uri_attrs[$k])) {
                     $this->attr_values[$k] = $uri_attrs[$k];
                     break;
                 }
             case "user":
                 if (isset($user_attrs[$k])) {
                     $this->attr_values[$k] = $user_attrs[$k];
                     break;
                 }
             case "domain":
                 if (isset($domain_attrs[$k])) {
                     $this->attr_values[$k] = $domain_attrs[$k];
                     break;
                 }
             case "global":
                 if (isset($global_attrs[$k])) {
                     $this->attr_values[$k] = $global_attrs[$k];
                     break;
                 }
         }
         /*
          *	If the value of attribute is not found, set it as null
          */
         if (!isset($this->attr_values[$k])) {
             $this->attr_values[$k] = null;
         }
     }
     // if option 'atributes' is not given, that mean we will work with all attributes
     if (empty($this->opt['attributes'])) {
         foreach ($this->attr_values as $k => $v) {
             // work only with attributes which have access to read
             if ($this->access_to_read($k)) {
                 $this->opt['attributes'][] = $k;
             }
         }
     } else {
         foreach ($this->opt['attributes'] as $k => $v) {
             if (!array_key_exists($v, $this->attr_values)) {
                 log_errors(PEAR::RaiseError("Attribute named '" . $v . "' does not exists"), $errors);
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //except unwanted arguments
     $this->opt['attributes'] = array_diff($this->opt['attributes'], $this->opt['exclude_attributes']);
     //save avaiable attrs before are filtered by group
     $this->all_avaiable_attrs = $this->opt['attributes'];
     if (!empty($this->opt['attrs_group'])) {
         foreach ($this->opt['attributes'] as $k => $v) {
             // work only with attributes from specified group
             if ($this->attr_types[$v]->get_group() != $this->opt['attrs_group']) {
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //set options to attributes
     foreach ($this->opt['attributes'] as $att) {
         if (isset($this->opt['attrs_options'][$att]) and is_array($this->opt['attrs_options'][$att])) {
             foreach ($this->opt['attrs_options'][$att] as $k => $v) {
                 $this->attr_types[$att]->set_opt($k, $v);
             }
         }
     }
     // add elements to form object
     foreach ($this->opt['attributes'] as $att) {
         if (!$this->access_to_change($att)) {
             continue;
         }
         //if attribute cannot be changed, do not add it ot the form
         $opt = array();
         $opt['err_msg'] = isset($this->opt['error_messages'][$att]) ? $this->opt['error_messages'][$att] : null;
         $this->attr_types[$att]->form_element($this->f, $this->attr_values[$att], $opt);
         $this->js_on_subm .= $this->attr_types[$att]->validation_js_before();
         $this->js_on_subm_2 .= $this->attr_types[$att]->validation_js_after();
     }
     if (!empty($this->opt['validate_js_funct'])) {
         $this->js_on_subm_2 .= $this->opt['validate_js_funct'];
     }
 }
Example #6
0
 /**
  * Perform the actual parsing
  *
  * @return boolean true on success
  */
 public function parse()
 {
     if (!is_resource($this->parser)) {
         return PEAR::raiseError("Can't create XML parser");
     }
     if (!is_resource($this->fp)) {
         return PEAR::raiseError("No valid input file");
     }
     while ($data = fread($this->fp, 4096)) {
         if (!xml_parse($this->parser, $data, feof($this->fp))) {
             $this->error = PEAR::RaiseError(xml_error_string(xml_get_error_code($this->parser)) . " " . $this->posString());
         }
         if ($this->error) {
             return $this->error;
         }
     }
     $stat = $this->error ? $this->error : true;
     return $stat;
 }
Example #7
0
 public static function getDialekt($int_dia)
 {
     return PEAR::RaiseError("bum", 444);
 }
Example #8
0
 /**
  * &factory
  * Creates and returns a new Translator object
  *
  * @param mixed $options
  * @access public
  * @return void
  */
 function &factory($options)
 {
     if (isset($options['dsn'])) {
         $options['conn'] =& MDB2::connect($options['dsn']);
         if (PEAR::isError($options['conn'])) {
             return $options['conn'];
         }
         unset($options['dsn']);
     } elseif (!isset($options['conn'])) {
         return PEAR::RaiseError("Translator::factory - Option 'conn' or 'dsn' must be given in Translator options parameter array");
     }
     $obj =& new Translator_MDB2();
     $obj->init($options);
     return $obj;
 }
Example #9
0
 /**
  * Support method for initDateFilters() -- build a spatial filter query based on a range
  * of dates (expressed as days from unix epoch).
  * See the index schema definition for more information.
  *
  * @param string $field field to use for filtering.
  * @param string $from  year or date (yyyy-mm-dd) for start of range.
  * @param string $to    year or date (yyyy-mm-dd) for end of range.
  * @param string $type  'overlap'  = document duration overlaps query durration (default)
  *                      'within '  = document duration within query durration
  *
  * @return string       filter query.
  * @access protected
  */
 protected function buildSpatialDateRangeFilter($field, $from, $to, $type = 'overlap')
 {
     $minFrom = -4371587;
     $maxTo = 2932896;
     $type = in_array($type, array('overlap', 'within')) ? $type : 'overlap';
     $this->spatialDateRangeFilterType = $type;
     $oldTZ = date_default_timezone_get();
     try {
         date_default_timezone_set('UTC');
         if ($from == '' || $from == '*') {
             $from = $minFrom;
         } else {
             // Make sure year has four digits
             if (preg_match('/^(-?)(\\d+)(.*)/', $from, $matches)) {
                 $from = $matches[1] . str_pad($matches[2], 4, '0', STR_PAD_LEFT) . $matches[3];
             }
             // A crude check to see if this is a complete date to accommodate different years
             // (1990, -12 etc.)
             if (strlen($from) < 10) {
                 $from .= '-01-01';
             }
             $fromDate = new DateTime("{$from}T00:00:00");
             // Need format instead of getTimestamp for dates before epoch
             $from = $fromDate->format('U') / 86400;
         }
         if ($to == '' || $to == '*') {
             $to = $maxTo;
         } else {
             // Make sure year has four digits
             if (preg_match('/^(-?)(\\d+)(.*)/', $to, $matches)) {
                 $to = $matches[1] . str_pad($matches[2], 4, '0', STR_PAD_LEFT) . $matches[3];
             }
             // A crude check to see if this is a complete date to accommodate different years
             // (1990, -12 etc.)
             if (strlen($to) < 10) {
                 $to .= '-12-31';
             }
             $toDate = new DateTime("{$to}T00:00:00");
             // Need format instead of getTimestamp for dates before epoch
             $to = $toDate->format('U') / 86400;
             // days since epoch
         }
     } catch (Exception $e) {
         date_default_timezone_set($oldTZ);
         return '';
     }
     date_default_timezone_set($oldTZ);
     if ($from > $to) {
         PEAR::RaiseError(new PEAR_Error("Invalid date range specified."));
     }
     // Assume Solr syntax -- this should be overridden in child classes where
     // other indexing methodologies are used.
     if ($type == 'overlap') {
         // document duration overlaps query duration
         // q=fieldX:"Intersects(-โˆž start end โˆž)"
         $query = "{$field}:[\"{$minFrom} {$from}\" TO \"{$to} {$maxTo}\"]";
     } else {
         if ($type == 'within') {
             // document duration within query duration
             // q=fieldX:"Intersects(start -โˆž โˆž end)"
             // Enlarge query range to match records with exactly the same time range as the original query
             $from -= 0.5;
             $to += 0.5;
             $query = "{$field}:[\"{$from} {$minFrom}\" TO \"{$maxTo} {$to}\"]";
         }
     }
     return $query;
 }