コード例 #1
0
ファイル: filters.php プロジェクト: nemein/openpsa
 /**
  * Handle the request for editing contact list
  *
  * @param String $handler_id    Name of the request handler
  * @param array $args           Variable arguments
  * @param array &$data          Public request data, passed by reference
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     // Get the current user
     $this->_person = new midcom_db_person(midcom_connection::get_user());
     $this->_person->require_do('midgard:update');
     // Load the controller
     $data['controller'] = $this->get_controller('simple', $this->_person);
     // Process the form
     switch ($data['controller']->process_form()) {
         case 'save':
         case 'cancel':
             if (isset($_GET['org_openpsa_calendar_returnurl'])) {
                 $url = $_GET['org_openpsa_calendar_returnurl'];
             } else {
                 $url = '';
             }
             return new midcom_response_relocate($url);
     }
     // Add the breadcrumb pieces
     if (isset($_GET['org_openpsa_calendar_returnurl'])) {
         $this->add_breadcrumb($_GET['org_openpsa_calendar_returnurl'], $this->_l10n->get('calendar'));
     }
     $this->add_breadcrumb('filters/', $this->_l10n->get('choose calendars'));
 }
コード例 #2
0
ファイル: task.php プロジェクト: nemein/openpsa
 public function _on_creating()
 {
     $this->_locale_set();
     $this->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_TASK;
     if (!$this->manager) {
         $this->manager = midcom_connection::get_user();
     }
     return $this->_prepare_save();
 }
コード例 #3
0
ファイル: viewer.php プロジェクト: nemein/openpsa
 public static function initialize_index_article($topic)
 {
     $page = new net_nemein_wiki_wikipage();
     $page->topic = $topic->id;
     $page->name = 'index';
     $page->title = $topic->extra;
     $page->content = midcom::get('i18n')->get_string('wiki default page content', 'net.nemein.wiki');
     $page->author = midcom_connection::get_user();
     if ($page->create()) {
         return $page;
     }
     return false;
 }
コード例 #4
0
ファイル: email.php プロジェクト: nemein/openpsa
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 private function _create_article($title)
 {
     $this->_article = new midcom_db_article();
     $author = $this->_find_email_person($this->_request_data['from']);
     if (!$author) {
         debug_add("Author '{$this->_request_data['from']}' not found", MIDCOM_LOG_WARN);
         if ($this->_config->get('api_email_abort_authornotfound') !== false) {
             throw new midcom_error("Author '{$this->_request_data['from']}' not found");
         }
         $this->_article->author = midcom_connection::get_user();
     } else {
         // TODO: This code needs a bit of rethinking
         $author_user = midcom::get('auth')->get_user($author->guid);
         if (!$this->_content_topic->can_do('midgard:create', $author_user)) {
             throw new midcom_error('Author doesn\'t have posting privileges');
         }
         $this->_article->author = $author->id;
     }
     //Default to first user in DB if author is not set
     if (!$this->_article->author) {
         $qb = midcom_db_person::new_query_builder();
         $qb->add_constraint('username', '<>', '');
         $qb->set_limit(1);
         $results = $qb->execute();
         unset($qb);
         if (empty($results)) {
             //No users found
             throw new midcom_error('Cannot set any author for the article');
         }
         $this->_article->author = $results[0]->id;
     }
     $resolver = new midcom_helper_reflector_nameresolver($this->_article);
     $this->_article->topic = $this->_content_topic->id;
     $this->_article->title = $title;
     $this->_article->allow_name_catenate = true;
     $this->_article->name = $resolver->generate_unique_name('title');
     if (empty($this->_article->name)) {
         debug_add('Could not generate unique name for the new article from title, using timestamp', MIDCOM_LOG_INFO);
         $this->_article->name = time();
         $resolver = new midcom_helper_reflector_nameresolver($this->_article);
         if (!$resolver->name_is_unique()) {
             throw new midcom_error('Failed to create unique name for the new article, aborting.');
         }
     }
     if (!$this->_article->create()) {
         debug_print_r('Failed to create article:', $this->_article);
         throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     $this->_article->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_email_schema'));
     return true;
 }
コード例 #5
0
ファイル: admin.php プロジェクト: nemein/openpsa
 /**
  * Internal helper, fires up the creation mode controller. Any error triggers a 500.
  */
 private function _load_create_controller()
 {
     $this->_defaults['task'] = $this->_request_data['task'];
     $this->_defaults['person'] = midcom_connection::get_user();
     $this->_defaults['date'] = time();
     $this->_controller = midcom_helper_datamanager2_controller::create('create');
     $this->_controller->schemadb =& $this->_schemadb;
     $this->_controller->schemaname = $this->_schema;
     $this->_controller->defaults = $this->_defaults;
     $this->_controller->callback_object =& $this;
     if (!$this->_controller->initialize()) {
         throw new midcom_error("Failed to initialize a DM2 create controller.");
     }
 }
コード例 #6
0
ファイル: loginTest.php プロジェクト: nemein/openpsa
 public function testLogin()
 {
     $auth = midcom::get('auth');
     $stat = $auth->login(self::$_username, self::$_password);
     $this->assertTrue($stat);
     $auth->_sync_user_with_backend();
     $this->assertTrue($auth->is_valid_user());
     $user = $auth->user;
     $this->assertTrue($user instanceof midcom_core_user);
     $this->assertEquals(self::$_person->guid, $user->guid);
     $this->assertEquals(self::$_person->id, midcom_connection::get_user());
     $auth->logout();
     $this->assertTrue(is_null($auth->user));
     $this->assertFalse($auth->is_valid_user());
 }
コード例 #7
0
ファイル: report.php プロジェクト: nemein/openpsa
 private function _prepare_save()
 {
     //Make sure our hours property is a float
     $this->hours = (double) $this->hours;
     $this->hours = round($this->hours, 2);
     //Make sure date is set
     if (!$this->date) {
         $this->date = time();
     }
     //Make sure person is set
     if (!$this->person) {
         $this->person = midcom_connection::get_user();
     }
     return true;
 }
コード例 #8
0
ファイル: create.php プロジェクト: nemein/openpsa
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_page = new net_nemein_wiki_wikipage();
     $this->_page->topic = $this->_topic->id;
     $this->_page->title = $this->_wikiword;
     $this->_page->author = midcom_connection::get_user();
     // We can clear the session now
     $this->_request_data['session']->remove('wikiword');
     if (!$this->_page->create()) {
         debug_print_r('We operated on this object:', $this->_page);
         throw new midcom_error('Failed to create a new page. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     $this->_page = new net_nemein_wiki_wikipage($this->_page->id);
     return $this->_page;
 }
コード例 #9
0
ファイル: expense.php プロジェクト: nemein/openpsa
 private function _prepare_save()
 {
     //Make sure date is set
     if (!$this->date) {
         $this->date = time();
     }
     //Make sure person is set
     if (!$this->person) {
         $this->person = midcom_connection::get_user();
     }
     //Is task is not set abort
     if (!$this->task) {
         return false;
     }
     return true;
 }
コード例 #10
0
ファイル: workingon.php プロジェクト: nemein/openpsa
 /**
  * Function to list invoiceable and uninvoicable hours
  */
 private function _list_work_hours()
 {
     $hours_mc = org_openpsa_projects_hour_report_dba::new_collector('person', midcom_connection::get_user());
     $hours_mc->add_value_property('task');
     $hours_mc->add_value_property('invoiceable');
     $hours_mc->add_value_property('hours');
     $hours_mc->add_constraint('date', '>=', $this->_request_data['week_start']);
     $hours_mc->add_constraint('date', '<=', $this->_request_data['week_end']);
     $hours_mc->execute();
     $hours = $hours_mc->list_keys();
     $this->_request_data['customers'] = array();
     $this->_request_data['hours'] = array('invoiceable' => array(), 'uninvoiceable' => array(), 'total_invoiceable' => 0, 'total_uninvoiceable' => 0);
     foreach ($hours as $guid => $values) {
         $this->_add_hour_data($hours_mc->get($guid));
     }
     return true;
 }
コード例 #11
0
ファイル: view.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_view($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $this->_person = new org_openpsa_contacts_person_dba($args[0]);
     $data['view'] = midcom_helper_datamanager2_handler::get_view_controller($this, $this->_person);
     $this->add_breadcrumb('', $this->_person->get_label());
     $auth = midcom::get('auth');
     if ($this->_person->id == midcom_connection::get_user() || $auth->can_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface')) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "edit/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get("edit"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:update'), MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "delete/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get("delete"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:delete')));
         if (midcom_connection::is_user($this->_person)) {
             $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "privileges/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("permissions"), MIDCOM_TOOLBAR_ICON => 'midgard.admin.asgard/permissions-16.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:privileges')));
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/notifications/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("notification settings"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock-discussion.png', MIDCOM_TOOLBAR_ENABLED => $this->_person->can_do('midgard:update')));
     }
     $this->bind_view_to_object($this->_person);
 }
コード例 #12
0
ファイル: projects.php プロジェクト: nemein/openpsa
 private function _generate_invoice()
 {
     $invoice = new org_openpsa_invoices_invoice_dba();
     $invoice->customer = (int) $_POST['org_openpsa_invoices_invoice_customer'];
     $invoice->number = $invoice->generate_invoice_number();
     $invoice->owner = midcom_connection::get_user();
     $invoice->vat = $invoice->get_default('vat');
     $invoice->description = $invoice->get_default('remarks');
     if (!$invoice->create()) {
         midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.invoices'), $this->_l10n->get('failed to create invoice, reason ') . midcom_connection::get_error_string(), 'error');
         return false;
     }
     // create invoice_items
     foreach ($_POST['org_openpsa_invoices_invoice_tasks'] as $task_id => $invoiceable) {
         if (!$invoiceable) {
             continue;
         }
         $task = $this->_tasks[$task_id];
         //instance the invoice_items
         $item = new org_openpsa_invoices_invoice_item_dba();
         $item->task = $task_id;
         try {
             $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($task->agreement);
             $item->deliverable = $deliverable->id;
         } catch (midcom_error $e) {
             $e->log();
         }
         $item->invoice = $invoice->id;
         $item->description = $task->title;
         $item->pricePerUnit = (double) $_POST['org_openpsa_invoices_invoice_tasks_price'][$task_id];
         $item->units = (double) $_POST['org_openpsa_invoices_invoice_tasks_units'][$task_id];
         $item->create();
         // Connect invoice to the tasks involved
         org_openpsa_projects_workflow::mark_invoiced($task, $invoice);
     }
     // Generate "Send invoice" task
     $invoice_sender_guid = $this->_config->get('invoice_sender');
     if (!empty($invoice_sender_guid)) {
         $invoice->generate_invoicing_task($invoice_sender_guid);
     }
     midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.invoices'), sprintf($this->_l10n->get('invoice %s created'), $invoice->get_label()), 'ok');
     midcom::get()->relocate("invoice/edit/{$invoice->guid}/");
     // This will exit
 }
コード例 #13
0
ファイル: edit.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     $this->_person = new org_openpsa_contacts_person_dba($args[0]);
     if ($this->_person->id != midcom_connection::get_user()) {
         midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     }
     $data['controller'] = $this->get_controller('simple', $this->_person);
     switch ($data['controller']->process_form()) {
         case 'save':
             midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), sprintf($this->_l10n->get('person %s saved'), $this->_person->name));
             // Fall-through
         // Fall-through
         case 'cancel':
             return new midcom_response_relocate('view/' . $this->_person->guid . '/');
     }
     $this->add_breadcrumb('', sprintf($this->_l10n_midcom->get('edit %s'), $this->_person->get_label()));
     org_openpsa_helpers::dm2_savecancel($this);
     $this->bind_view_to_object($this->_person);
 }
コード例 #14
0
ファイル: _sessioning.php プロジェクト: nemein/openpsa
 private function _initialize($unconditional_start = false)
 {
     static $initialized = false;
     if ($initialized) {
         return true;
     }
     if (!$GLOBALS['midcom_config']['sessioning_service_enable'] && !($GLOBALS['midcom_config']['sessioning_service_always_enable_for_users'] && midcom_connection::get_user())) {
         return false;
     }
     // Try to start session only if the client sends the id OR we need to set data
     if (!isset($_REQUEST[session_name()]) && !$unconditional_start) {
         return false;
     }
     if (_midcom_headers_sent()) {
         // Don't try starting a session if we're past the headers phase
         debug_add("Aborting session start, headers have already been sent", MIDCOM_LOG_WARN);
         return;
     }
     $track_state = ini_get('track_errors');
     ini_set('track_errors', true);
     @session_start();
     $session_err = null;
     if (isset($php_errormsg)) {
         $session_err = (string) $php_errormsg;
     }
     ini_set('track_errors', $track_state);
     unset($track_state);
     if (!isset($_SESSION)) {
         debug_add("\$_SESSION is not set, error message was: {$session_err}", MIDCOM_LOG_ERROR);
         unset($session_err, $php_errormsg);
         return false;
     }
     unset($session_err);
     /* Cache disabling made conditional based on domain/key existence */
     // Check for session data and load or initialize it, if necessary
     if (!array_key_exists('midcom_session_data', $_SESSION)) {
         $_SESSION['midcom_session_data'] = array();
         $_SESSION['midcom_session_data']['midcom.service.sessioning']['startup'] = serialize(time());
     }
     $initialized = true;
     return true;
 }
コード例 #15
0
ファイル: invoice.php プロジェクト: nemein/openpsa
 /**
  * Generate "Send invoice" task
  */
 function generate_invoicing_task($invoicer)
 {
     try {
         $invoice_sender = new midcom_db_person($invoicer);
     } catch (midcom_error $e) {
         return;
     }
     $config = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config');
     $task = new org_openpsa_projects_task_dba();
     $task->get_members();
     $task->resources[$invoice_sender->id] = true;
     $task->manager = midcom_connection::get_user();
     // TODO: Connect the customer as the contact?
     $task->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_TASK;
     $task->title = sprintf(midcom::get('i18n')->get_string('send invoice %s', 'org.openpsa.invoices'), sprintf($config->get('invoice_number_format'), sprintf($config->get('invoice_number_format'), $this->number)));
     // TODO: Store link to invoice into description
     $task->end = time() + 24 * 3600;
     if ($task->create()) {
         org_openpsa_relatedto_plugin::create($task, 'org.openpsa.projects', $this, 'org.openpsa.invoices');
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.invoices', 'org.openpsa.invoices'), sprintf(midcom::get('i18n')->get_string('created "%s" task to %s', 'org.openpsa.invoices'), $task->title, $invoice_sender->name), 'ok');
     }
 }
コード例 #16
0
ファイル: agenda.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_day($handler_id, array $args, array &$data)
 {
     // Generate start/end timestamps for the day
     $requested_time = @strtotime($args[0]);
     if (!$requested_time) {
         throw new midcom_error('could not generate time from ' . $args[0]);
     }
     // Use calendar widget for time calculations
     $this->_request_data['calendar'] = new org_openpsa_widgets_calendar(date('Y', $requested_time), date('m', $requested_time), date('d', $requested_time));
     $this->_request_data['calendar']->type = org_openpsa_widgets_calendar::DAY;
     $from = $this->_request_data['calendar']->get_day_start();
     $to = $this->_request_data['calendar']->get_day_end();
     // List user's event memberships
     $mc = midcom_db_eventmember::new_collector('uid', midcom_connection::get_user());
     // Find all events that occur during [$from, $end]
     $mc->begin_group("OR");
     // The event begins during [$from, $to]
     $mc->begin_group("AND");
     $mc->add_constraint("eid.start", ">=", $from);
     $mc->add_constraint("eid.start", "<=", $to);
     $mc->end_group();
     // The event begins before and ends after [$from, $to]
     $mc->begin_group("AND");
     $mc->add_constraint("eid.start", "<=", $from);
     $mc->add_constraint("eid.end", ">=", $to);
     $mc->end_group();
     // The event ends during [$from, $to]
     $mc->begin_group("AND");
     $mc->add_constraint("eid.end", ">=", $from);
     $mc->add_constraint("eid.end", "<=", $to);
     $mc->end_group();
     $mc->end_group();
     $eventmembers = $mc->get_values('eid');
     $this->_request_data['events'] = array();
     foreach ($eventmembers as $eid) {
         $this->_request_data['events'][] = new org_openpsa_calendar_event_dba($eid);
     }
 }
コード例 #17
0
ファイル: delete.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     $this->_person = new midcom_db_person($args[0]);
     if ($this->_person->id != midcom_connection::get_user()) {
         midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     }
     if (array_key_exists('org_openpsa_user_deleteok', $_POST)) {
         $delete_succeeded = $this->_person->delete();
         if ($delete_succeeded) {
             // Update the index
             $indexer = midcom::get('indexer');
             $indexer->delete($this->_person->guid);
             return new midcom_response_relocate('');
         } else {
             // Failure, give a message
             midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), $this->_l10n->get("failed to delete person, reason") . ' ' . midcom_connection::get_error_string(), 'error');
             return new midcom_response_relocate('view/' . $this->_person->guid . '/');
         }
     }
     $data['view'] = midcom_helper_datamanager2_handler::get_view_controller($this, $this->_person);
     $data['person'] = $this->_person;
     $this->add_breadcrumb('', sprintf($this->_l10n_midcom->get('delete %s'), $this->_person->get_label()));
     $this->bind_view_to_object($this->_person);
 }
コード例 #18
0
ファイル: content.php プロジェクト: nemein/openpsa
 function cache_control_headers()
 {
     // Add Expiration and Cache Control headers
     $cache_control = false;
     $pragma = false;
     $expires = false;
     // Just to be sure not to mess the headers sent by no_cache in case it was called
     if (!$this->_no_cache) {
         // Typecast to make copy in stead of reference
         $strategy = (string) $this->_headers_strategy;
         $default_lifetime = (int) $this->_default_lifetime;
         if (midcom::get('auth')->is_valid_user() || !midcom_connection::get_user()) {
             // Typecast to make copy in stead of reference
             $strategy = (string) $this->_headers_strategy_authenticated;
             $default_lifetime = (int) $this->_default_lifetime_authenticated;
         }
         switch ($strategy) {
             // included in case _headers_strategy_authenticated sets this
             case 'no-cache':
                 $this->no_cache();
                 break;
             case 'revalidate':
                 // Currently, we *force* a cache client to revalidate the copy every time.
                 // I hope that this fixes most of the problems outlined in #297 for the time being.
                 // The timeout of a content cache entry is not affected by this.
                 $cache_control = 'max-age=0 must-revalidate';
                 $expires = time();
                 break;
             case 'private':
                 // Fall-strough intentional
             // Fall-strough intentional
             case 'public':
                 if (!is_null($this->_expires)) {
                     $expires = $this->_expires;
                     $max_age = $this->_expires - time();
                 } else {
                     $expires = time() + $default_lifetime;
                     $max_age = $default_lifetime;
                 }
                 $cache_control = "{$strategy} max-age={$max_age}";
                 if ($max_age == 0) {
                     $cache_control .= ' must-revalidate';
                 }
                 $pragma =& $strategy;
                 break;
         }
     }
     if ($cache_control !== false) {
         $header = "Cache-Control: {$cache_control}";
         _midcom_header($header);
         $this->_sent_headers[] = $header;
     }
     if ($pragma !== false) {
         $header = "Pragma: {$pragma}";
         _midcom_header($header);
         $this->_sent_headers[] = $header;
     }
     if ($expires !== false) {
         $header = "Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT";
         _midcom_header($header);
         $this->_sent_headers[] = $header;
     }
 }
コード例 #19
0
ファイル: crud.php プロジェクト: nemein/openpsa
 public function _load_defaults()
 {
     $this->_defaults['manager'] = midcom_connection::get_user();
 }
コード例 #20
0
ファイル: sessionmgr.php プロジェクト: nemein/openpsa
 /**
  * Creates a login session using the given arguments. Returns a session identifier.
  * The call will validate the passed credentials and thus authenticate for the given
  * user at the same time, so there is no need to call authenticate_session() after
  * creating it. A failed password check will of course not create a login session.
  *
  * @param string $username The name of the user to store with the session.
  * @param string $password The clear text password to store with the session.
  * @param string $clientip The client IP to which this session is assigned to. This
  *     defaults to the client IP reported by Apache.
  * @return Array An array holding the session identifier in the 'session_id' key and
  *     the associated user in the 'user' key (take this by reference!). Failure returns false.
  */
 public function create_login_session($username, $password, $clientip = null)
 {
     if ($clientip === null) {
         $clientip = $_SERVER['REMOTE_ADDR'];
     }
     if (!$this->_do_midgard_auth($username, $password)) {
         debug_add('Failed to create a new login session: Authentication Failure', MIDCOM_LOG_ERROR);
         return false;
     }
     if (!($user = $this->auth->get_user($this->person))) {
         debug_add("Failed to create a new login session: User ID " . midcom_connection::get_user() . " is invalid.", MIDCOM_LOG_ERROR);
         return false;
     }
     $session = new midcom_core_login_session_db();
     $session->userid = $user->id;
     $session->username = $username;
     $session->password = $this->_obfuscate_password($password);
     $session->clientip = $clientip;
     $session->timestamp = time();
     if (!$session->create()) {
         debug_add('Failed to create a new login session: ' . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
         return false;
     }
     $result = array('session_id' => $session->guid, 'user' => $user);
     $this->current_session_id = $session->guid;
     $this->_loaded_sessions[$session->guid] = $session;
     return $result;
 }
コード例 #21
0
    <td>
    <?php 
if (isset($data['priority_array']) && array_key_exists($task->priority, $data['priority_array'])) {
    echo $data['l10n']->get($data['priority_array'][$task->priority]);
}
?>
    </td>
    <td><?php 
echo strftime("%x", $project->start);
?>
</td>
    <td><?php 
echo strftime("%x", $project->end);
?>
</td>
    <td>
  <?php 
if (array_key_exists(midcom_connection::get_user(), $project->resources)) {
    echo $data['l10n']->get('you are project participant');
} else {
    if (array_key_exists(midcom_connection::get_user(), $project->contacts)) {
        echo $data['l10n']->get('you are project subscriber');
        echo '<form method="post" class="subscribe" action="' . $prefix . 'project/unsubscribe/' . $project->guid . '/"><input type="submit" class="unsubscribe" value="' . $data['l10n']->get('unsubscribe') . '" /></form>';
    } else {
        echo $data['l10n']->get('you are not subscribed to project');
        echo '<form method="post" class="subscribe" action="' . $prefix . 'project/subscribe/' . $project->guid . '/"><input type="submit" value="' . $data['l10n']->get('subscribe') . '" /></form>';
    }
}
?>
  </td>
</tr>
コード例 #22
0
ファイル: crud.php プロジェクト: nemein/openpsa
 function _load_defaults()
 {
     $this->_defaults['date'] = time();
     $this->_defaults['deliverydate'] = time();
     // Set default due date and copy customer remarks to invoice description
     if (array_key_exists('customer', $this->_request_data)) {
         $dummy = new org_openpsa_invoices_invoice_dba();
         $dummy->customer = $this->_request_data['customer']->id;
         $this->_defaults['vat'] = $dummy->get_default('vat');
         if (is_a($this->_request_data['customer'], 'org_openpsa_contacts_person_dba')) {
             $this->_defaults['customerContact'] = $this->_request_data['customer']->id;
         }
         // we got a customer, set description default
         $this->_defaults['description'] = $dummy->get_default('remarks');
         unset($dummy);
     } else {
         $due_date = $this->_config->get('default_due_days') * 3600 * 24 + time();
         $this->_defaults['due'] = $due_date;
     }
     // Generate invoice number
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator');
     $calculator = new $client_class();
     $this->_defaults['number'] = $calculator->generate_invoice_number();
     $this->_defaults['owner'] = midcom_connection::get_user();
 }
コード例 #23
0
ファイル: workflow.php プロジェクト: nemein/openpsa
 /**
  * Connect the task hour reports to an invoice
  *
  * @param org_openpsa_projects_task_dba &$task The task we're working on
  * @param org_openpsa_invoices_invoice_dba &$invoice The invoice we're working on
  */
 static function mark_invoiced(&$task, &$invoice)
 {
     debug_add("task->mark_invoiced() called with user #" . midcom_connection::get_user());
     try {
         $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($task->agreement);
     } catch (midcom_error $e) {
         $e->log();
     }
     // Mark the hour reports invoiced
     $hours_marked = 0;
     $qb = org_openpsa_projects_hour_report_dba::new_query_builder();
     $qb->add_constraint('task', '=', $task->id);
     $qb->add_constraint('invoice', '=', 0);
     $qb->add_constraint('invoiceable', '=', true);
     // Check how the agreement deals with hour reports
     if ($deliverable && $deliverable->invoiceApprovedOnly) {
         // The agreement allows invoicing only approved hours, therefore don't mark unapproved
         $qb->add_constraint('metadata.isapproved', '=', true);
     }
     $reports = $qb->execute();
     foreach ($reports as $report) {
         $report->invoice = $invoice->id;
         $report->_skip_parent_refresh = true;
         if ($report->update()) {
             $hours_marked += $report->hours;
         }
     }
     // Update hour caches to agreement
     if (!$task->update_cache()) {
         debug_add('Failed to update task hour caches, last Midgard error: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN);
     }
     // Notify user
     midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.projects', 'org.openpsa.projects'), sprintf(midcom::get('i18n')->get_string('marked %s hours as invoiced in task "%s"', 'org.openpsa.projects'), $hours_marked, $task->title), 'ok');
     return $hours_marked;
 }
コード例 #24
0
ファイル: manual.php プロジェクト: nemein/openpsa
 /**
  * Import manually entered log entry. The entries are associative arrays containing
  * some or all of the following keys:
  *
  * - latitude
  * - longitude
  * - altitude
  * - city
  * - country
  * - aerodrome
  * - timestamp
  *
  * @param Array $log Log entry in Array format specific to importer
  * @return boolean Indicating success.
  */
 function import($log)
 {
     $this->log = new org_routamc_positioning_log_dba();
     $this->log->importer = 'manual';
     // Set different person if required
     if (array_key_exists('person', $log)) {
         $this->log->person = $log['person'];
     } else {
         $this->log->person = midcom_connection::get_user();
     }
     if (array_key_exists('timestamp', $log)) {
         $this->log->date = (int) $log['timestamp'];
     } else {
         $this->log->date = time();
     }
     // Figure out which option we will use, starting from best option
     // Best option: we know coordinates
     if (array_key_exists('latitude', $log) && array_key_exists('longitude', $log)) {
         // Manually entered positions are assumed to be only semi-accurate
         $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_MANUAL;
         // Normalize coordinates to decimal
         $coordinates = $this->normalize_coordinates($log['latitude'], $log['longitude']);
         $this->log->latitude = $coordinates['latitude'];
         $this->log->longitude = $coordinates['longitude'];
     }
     // Airport entered
     if (array_key_exists('aerodrome', $log)) {
         // Aerodrome position is not usually very accurate, except if we're at the airport of course
         $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_CITY;
         // Normalize aerodrome name
         $aerodrome = strtoupper($log['aerodrome']);
         // Seek the aerodrome entry, first by accurate match
         $aerodrome_entry = null;
         $qb = org_routamc_positioning_aerodrome_dba::new_query_builder();
         $qb->begin_group('OR');
         // We will seek by both ICAO and IATA codes
         $qb->add_constraint('icao', '=', $aerodrome);
         $qb->add_constraint('iata', '=', $aerodrome);
         $qb->end_group();
         $matches = $qb->execute();
         if (count($matches) > 0) {
             $aerodrome_entry = $matches[0];
         }
         if (is_null($aerodrome_entry)) {
             // Couldn't match the entered city to a location
             $this->error = 'POSITIONING_AERODROME_NOT_FOUND';
             return false;
         }
         // Normalize coordinates
         $this->log->latitude = $aerodrome_entry->latitude;
         $this->log->longitude = $aerodrome_entry->longitude;
         $this->log->altitude = $aerodrome_entry->altitude;
     }
     // City and country entered
     if (array_key_exists('city', $log)) {
         if (!isset($log['geocoder'])) {
             $log['geocoder'] = 'city';
         }
         $geocoder = org_routamc_positioning_geocoder::create($log['geocoder']);
         $position = $geocoder->geocode($log);
         if (!$position['latitude'] || !$position['longitude']) {
             // Couldn't match the entered city to a location
             $this->error = 'POSITIONING_CITY_NOT_FOUND';
             return false;
         }
         foreach ($position as $key => $value) {
             $this->log->{$key} = $value;
         }
     }
     // Save altitude if provided
     if (array_key_exists('altitude', $log)) {
         $this->log->altitude = $log['altitude'];
     }
     // Try to create the entry
     $stat = $this->log->create();
     $this->error = midcom_connection::get_error_string();
     return $stat;
 }
コード例 #25
0
ファイル: main.php プロジェクト: nemein/openpsa
 /**
  * Internal startup helper, synchronizes the authenticated user with the Midgard Authentication
  * for startup. This will be overridden by MidCOM Auth, but is there for compatibility reasons.
  */
 private function _initialize_user_from_midgard()
 {
     if (midcom_connection::get_user() && ($user = $this->get_user(midcom_connection::get_user()))) {
         $this->user = $user;
         if (midcom_connection::is_admin() || midcom_connection::get('root')) {
             $this->admin = true;
         }
     }
 }
コード例 #26
0
ファイル: view.php プロジェクト: nemein/openpsa
 /**
  * Populate the calendar with resources
  *
  * @param midcom_db_person $resource
  * @param int $from Start time
  * @param int $to End time
  */
 private function _populate_calendar_resource($resource, $from, $to)
 {
     $resource_array = array('name' => $resource->firstname . ' ' . $resource->lastname, 'reservations' => array());
     if ($resource->id == midcom_connection::get_user()) {
         $resource_array['name'] = $this->_l10n->get('me');
         $resource_array['css_class'] = 'blue';
     }
     $qb = org_openpsa_calendar_event_member_dba::new_query_builder();
     // Find all events that occur during [$from, $end]
     $qb->begin_group('OR');
     // The event begins during [$from, $to]
     $qb->begin_group('AND');
     $qb->add_constraint('eid.start', '>=', $from);
     $qb->add_constraint('eid.start', '<=', $to);
     $qb->end_group();
     // The event begins before and ends after [$from, $to]
     $qb->begin_group('AND');
     $qb->add_constraint('eid.start', '<=', $from);
     $qb->add_constraint('eid.end', '>=', $to);
     $qb->end_group();
     // The event ends during [$from, $to]
     $qb->begin_group('AND');
     $qb->add_constraint('eid.end', '>=', $from);
     $qb->add_constraint('eid.end', '<=', $to);
     $qb->end_group();
     $qb->end_group();
     $qb->add_constraint('eid.up', '=', $this->_root_event->id);
     $qb->add_constraint('uid', '=', (int) $resource->id);
     $memberships = $qb->execute();
     if ($memberships) {
         foreach ($memberships as $membership) {
             $event = new org_openpsa_calendar_event_dba($membership->eid);
             // Customize label
             $label_field = $this->_config->get('event_label');
             if (!$label_field) {
                 $label_field = 'title';
             }
             $label = $event->{$label_field};
             if ($label_field == 'creator') {
                 $user = midcom::get('auth')->get_user($event->metadata->creator);
                 $label = $user->name;
             }
             $resource_array['reservations'][$event->guid] = array('name' => $label, 'location' => $event->location, 'start' => $event->start, 'end' => $event->end, 'private' => false);
             if ($event->orgOpenpsaAccesstype == org_openpsa_core_acl::ACCESS_PRIVATE) {
                 $resource_array['reservations'][$event->id]['css_class'] = ' private';
                 $resource_array['reservations'][$event->id]['private'] = true;
             }
         }
     }
     return $resource_array;
 }
コード例 #27
0
ファイル: salesproject.php プロジェクト: nemein/openpsa
 public function _on_creating()
 {
     if (!$this->start) {
         $this->start = time();
     }
     if (!$this->status) {
         $this->status = self::STATUS_ACTIVE;
     }
     if (!$this->owner) {
         $this->owner = midcom_connection::get_user();
     }
     return true;
 }
コード例 #28
0
ファイル: preferences.php プロジェクト: nemein/openpsa
 /**
  * AJAX backend for saving data on the fly
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 public function _handler_ajax($handler_id, array $args, array &$data)
 {
     $this->_person = new midcom_db_person(midcom_connection::get_user());
     // Check for the ACL's
     $this->_person->require_do('midgard:update');
     // Patch for Midgard ACL problem of setting person's own parameters
     midcom::get('auth')->request_sudo('midgard.admin.asgard');
     foreach ($_POST as $key => $value) {
         if (is_array($value)) {
             $value = serialize($value);
         }
         if (!$this->_person->set_parameter('midgard.admin.asgard:preferences', $key, $value)) {
             $this->_status = false;
             midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), sprintf(midcom::get('i18n')->get_string('failed to save the preference for %s', 'midgard.admin.asgard'), midcom::get('i18n')->get_string($key, 'midgard.admin.asgard')));
         }
         debug_add("Added configuration key-value pair {$key} => {$value}");
     }
     midcom::get('auth')->drop_sudo();
 }
コード例 #29
0
ファイル: create.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_create($handler_id, array $args, array &$data)
 {
     $data['directory']->require_do('midgard:create');
     $this->_defaults = array('topic' => $this->_request_data['directory']->id, 'author' => midcom_connection::get_user(), 'orgOpenpsaAccesstype' => $this->_topic->get_parameter('org.openpsa.core', 'orgOpenpsaAccesstype'), 'orgOpenpsaOwnerWg' => $this->_topic->get_parameter('org.openpsa.core', 'orgOpenpsaOwnerWg'));
     $this->_load_create_controller();
     switch ($this->_controller->process_form()) {
         case 'save':
             /* Index the document */
             $indexer = new org_openpsa_documents_midcom_indexer($this->_topic);
             $indexer->index($this->_controller->datamanager);
             // Relocate to document view
             $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
             if ($this->_document->topic != $this->_topic->id) {
                 $nap = new midcom_helper_nav();
                 $node = $nap->get_node($this->_document->topic);
                 $prefix = $node[MIDCOM_NAV_ABSOLUTEURL];
             }
             return new midcom_response_relocate($prefix . "document/" . $this->_document->guid . "/");
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_request_data['controller'] =& $this->_controller;
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this);
     $this->add_breadcrumb("", $this->_l10n->get('create document'));
 }
コード例 #30
0
ファイル: view.php プロジェクト: nemein/openpsa
 /**
  * Helper function that populates the toolbar with the necessary items
  *
  * @param string $handler_id the ID of the current handler
  */
 private function _populate_toolbar($handler_id)
 {
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/edit/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('edit'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:update'), MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
     $siteconfig = org_openpsa_core_siteconfig::get_instance();
     $invoices_url = $siteconfig->get_node_full_url('org.openpsa.invoices');
     $user_url = $siteconfig->get_node_full_url('org.openpsa.user');
     if ($invoices_url && midcom::get('auth')->can_user_do('midgard:create', null, 'org_openpsa_invoices_invoice_dba')) {
         $billing_data_url = "create/" . $this->_contact->guid . "/";
         $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
         $qb_billing_data->add_constraint('linkGuid', '=', $this->_contact->guid);
         $billing_data = $qb_billing_data->execute();
         if (count($billing_data) > 0) {
             $billing_data_url = $billing_data[0]->guid . "/";
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => $invoices_url . "billingdata/" . $billing_data_url, MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit billingdata'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:update')));
     }
     if ($user_url && (midcom_connection::get_user() == $this->_contact->id || midcom::get('auth')->can_user_do('org.openpsa.user:access', null, 'org_openpsa_user_interface'))) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => $user_url . "view/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('user management', 'org.openpsa.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png'));
     }
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/delete/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('delete'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:delete'), MIDCOM_TOOLBAR_ACCESSKEY => 'd'));
     $mycontacts = new org_openpsa_contacts_mycontacts();
     if ($mycontacts->is_member($this->_contact->guid)) {
         // We're buddies, show remove button
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "mycontacts/remove/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('remove from my contacts'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png'));
     } else {
         // We're not buddies, show add button
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "mycontacts/add/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('add to my contacts'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_person.png'));
     }
 }