Example #1
0
 public function __get($field)
 {
     if (array_key_exists($field, $this->_services)) {
         return $this->_services[$field];
     }
     $instance = null;
     switch ($field) {
         case '_i18n':
             $instance = midcom::get('i18n');
             break;
         case '_l10n':
             $instance = midcom::get('i18n')->get_l10n($this->_component);
             break;
         case '_l10n_midcom':
             $instance = midcom::get('i18n')->get_l10n('midcom');
             break;
         case '_config':
             $instance = midcom_baseclasses_components_configuration::get($this->_component, 'config');
             break;
         default:
             debug_add('Component ' . $this->_component . ' tried to access nonexistant service "' . $field . '"', MIDCOM_LOG_ERROR);
             debug_print_function_stack('Called from here:');
             return false;
     }
     $this->_services[$field] = $instance;
     return $this->_services[$field];
 }
Example #2
0
 public function _on_updating()
 {
     // Allow root group membership creation only for admins (check update as well to avoid sneaky bastards
     if ($this->gid == 0) {
         if (midcom::get('auth')->admin) {
             debug_add("Group #0 membership creation only allowed for admins");
             debug_print_function_stack('Forbidden ROOT member creation called from');
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * Validates that there is an authenticated user.
  *
  * If this is not the case, the regular login page is shown automatically, see
  * show_login_page() for details..
  *
  * If the check is successful, the function returns silently.
  *
  * @param string $method Preferred authentication method: form or basic
  */
 function require_valid_user($method = 'form')
 {
     debug_print_function_stack("require_valid_user called at this level");
     if (!$this->is_valid_user()) {
         switch ($method) {
             case 'basic':
                 $this->_http_basic_auth();
                 break;
             case 'form':
             default:
                 $this->show_login_page();
                 // This will exit.
         }
     }
 }
Example #4
0
 /**
  * Access the MidCOM component context
  *
  * Returns Component Context Information associated to the component with the
  * context identified by $key.
  *
  * @param int $key  The key requested
  * @return mixed    The content of the key being requested.
  */
 public function get_key($key)
 {
     if (!array_key_exists($key, $this->_data) || $key >= 1000) {
         debug_add("Requested Key ID {$key} invalid.", MIDCOM_LOG_ERROR);
         debug_print_function_stack('Called from here');
         return false;
     }
     return $this->_data[$key];
 }
Example #5
0
 /**
  * Shortcut for creating status object
  *
  * @param org_openpsa_projects_task_dba &$task The task we're working on
  * @param integer $status The status to convert
  * @param integer $target_person The person ID, if any
  * @param string $comment The status comment, if any
  */
 public static function create_status(&$task, $status_type, $target_person = 0, $comment = '')
 {
     debug_print_function_stack('create_status called from: ');
     $status = new org_openpsa_projects_task_status_dba();
     if ($target_person != 0) {
         $status->targetPerson = $target_person;
     }
     $status->task = $task->id;
     $status->type = $status_type;
     //This shouldn't be needed
     $status->timestamp = $status->gmtime();
     $status->comment = $comment;
     $ret = $status->create();
     if (!$ret) {
         debug_add('failed to create status object, errstr: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN);
     }
     return $ret;
 }
Example #6
0
 /**
  * Runs a query where limit and offset is taken into account <i>prior</i> to
  * execution in the core.
  *
  * This is useful in cases where you can safely assume read privileges on all
  * objects, and where you would otherwise have to deal with huge resultsets.
  *
  * Be aware that this might lead to empty resultsets "in the middle" of the
  * actual full resultset when read privileges are missing.
  *
  * @see execute()
  */
 function execute_unchecked()
 {
     $this->_check_groups();
     $this->_reset();
     if (!call_user_func_array(array($this->_real_class, '_on_prepare_exec_query_builder'), array(&$this))) {
         debug_add('The _on_prepare_exec_query_builder callback returned false, so we abort now.');
         return null;
     }
     if ($this->_constraint_count == 0) {
         debug_add('This Query Builder instance has no constraints, see debug level log for stacktrace', MIDCOM_LOG_WARN);
         debug_print_function_stack('We were called from here:');
     }
     // Add the limit / offsets
     if ($this->_limit) {
         $this->_query->set_limit($this->_limit);
     }
     if ($this->_offset) {
         $this->_query->set_offset($this->_offset);
     }
     $newresult = $this->_execute_and_check_privileges();
     if (!is_array($newresult)) {
         return $newresult;
     }
     if ($this->_limit) {
         while (count($newresult) > $this->_limit) {
             array_pop($newresult);
         }
     }
     call_user_func_array(array($this->_real_class, '_on_process_query_result'), array(&$newresult));
     $this->count = count($newresult);
     return $newresult;
 }
Example #7
0
 /**
  * Sets a given key in the cache. If the data group is unknown, a Warning-Level error
  * is logged and putting is denied.
  *
  * @param string $data_group The Data Group to look in.
  * @param string $key The key to look up.
  * @param mixed $data The data to store.
  * @param int $timeout how long the data should live in the cache.
  */
 function put($data_group, $key, $data, $timeout = false)
 {
     if ($this->_cache === null) {
         return;
     }
     if (!in_array($data_group, $this->_data_groups)) {
         debug_add("Tried to add data to the unknown data group {$data_group}, cannot do that.", MIDCOM_LOG_WARN);
         debug_print_r('Known data groups:', $this->_data_groups);
         debug_print_function_stack('We were called from here:');
         return;
     }
     $this->_cache->put("{$data_group}-{$key}", $data, $timeout);
 }
Example #8
0
 /**
  * Show an error page.
  *
  * This function is a small helper, that will display a simple HTML Page reporting
  * the error described by $httpcode and $message. The $httpcode is also used to
  * send an appropriate HTTP Response.
  *
  * The error pages can be customized by creating style elements named midcom_error_$httpcode.
  *
  * For a list of the allowed HTTP codes see the MIDCOM_ERR... constants
  *
  * <b>Note:</b> This function will call _midcom_stop_request() after it is finished.
  *
  * @link http://www.midgard-project.org/documentation/styling-midcom-error-pages/ Styling MidCOM error pages
  * @param int $httpcode        The error code to send.
  * @param string $message    The message to print.
  */
 public function show($httpcode, $message)
 {
     if (!$this->_exception) {
         debug_add("An error has been generated: Code: {$httpcode}, Message: {$message}");
         debug_print_function_stack('Stacktrace:');
     }
     // Send error to special log or recipient as per in configuration.
     $this->send($httpcode, $message);
     if (_midcom_headers_sent()) {
         debug_add("Generate-Error was called after sending the HTTP Headers!", MIDCOM_LOG_ERROR);
         debug_add("Unexpected Error: {$httpcode} - {$message}", MIDCOM_LOG_ERROR);
         _midcom_stop_request("Unexpected Error, this should display an HTTP {$httpcode} - " . htmlentities($message));
     }
     switch ($httpcode) {
         case MIDCOM_ERROK:
             $header = "HTTP/1.0 200 OK";
             $title = "OK";
             $code = 200;
             break;
         case MIDCOM_ERRNOTFOUND:
             $header = "HTTP/1.0 404 Not Found";
             $title = "Not Found";
             $code = 404;
             break;
         case MIDCOM_ERRFORBIDDEN:
             // show access denied
             $this->access_denied($message);
             $header = "HTTP/1.0 403 Forbidden";
             $title = "Forbidden";
             $code = 403;
             break;
         case MIDCOM_ERRAUTH:
             $header = "HTTP/1.0 401 Unauthorized";
             $title = "Unauthorized";
             $code = 401;
             break;
         default:
             debug_add("Unknown Errorcode {$httpcode} encountered, assuming 500");
             // Fall-through
         // Fall-through
         case MIDCOM_ERRCRIT:
             $header = "HTTP/1.0 500 Server Error";
             $title = "Server Error";
             $code = 500;
             break;
     }
     _midcom_header($header);
     _midcom_header('Content-Type: text/html');
     $style = midcom::get('style');
     $style->data['error_title'] = $title;
     $style->data['error_message'] = $message;
     $style->data['error_code'] = $code;
     $style->data['error_exception'] = $this->_exception;
     $style->data['error_handler'] = $this;
     if (!$style->show_midcom('midcom_error_' . $code)) {
         $style->show_midcom('midcom_error');
     }
     debug_add("Error Page output finished, exiting now");
     midcom::get('cache')->content->no_cache();
     if (midcom::get()) {
         midcom::get()->finish();
     }
     _midcom_stop_request();
 }