Пример #1
0
/**
 * Simple default topic hierarchy setup for OpenPSA
 *
 * @package midcom
 */
function openpsa_prepare_topics()
{
    $openpsa_topics = array('Calendar' => 'org.openpsa.calendar', 'Contacts' => 'org.openpsa.contacts', 'Documents' => 'org.openpsa.documents', 'Expenses' => 'org.openpsa.expenses', 'Invoices' => 'org.openpsa.invoices', 'Products' => 'org.openpsa.products', 'Projects' => 'org.openpsa.projects', 'Reports' => 'org.openpsa.reports', 'Sales' => 'org.openpsa.sales', 'User Management' => 'org.openpsa.user', 'Wiki' => 'net.nemein.wiki');
    $qb = new midgard_query_builder('midgard_topic');
    $qb->add_constraint('name', '=', 'openpsa');
    $qb->add_constraint('up', '=', 0);
    $topics = $qb->execute();
    if ($topics) {
        return $topics[0]->guid;
    }
    // Create a new root topic for OpenPSA
    $root_topic = new midgard_topic();
    $root_topic->name = 'openpsa';
    $root_topic->component = 'org.openpsa.mypage';
    $root_topic->extra = 'OpenPSA';
    if (!$root_topic->create()) {
        throw new Exception('Failed to create root topic for OpenPSA: ' . midgard_connection::get_instance()->get_error_string());
    }
    foreach ($openpsa_topics as $title => $component) {
        $topic = new midgard_topic();
        $topic->name = strtolower(preg_replace('/\\W/', '-', $title));
        $topic->component = $component;
        $topic->extra = $title;
        $topic->up = $root_topic->id;
        $topic->create();
    }
    return $root_topic->guid;
}
Пример #2
0
 /**
  * Find hanging duplicate marks (that no longer point anywhere) and clear them
  */
 public function _on_execute()
 {
     debug_add('_on_execute called');
     if (!$this->_config->get('enable_duplicate_search')) {
         debug_add('Duplicate operations disabled, aborting', MIDCOM_LOG_INFO);
         return;
     }
     // Untill the FIXME below is handled we abort
     debug_add('Duplicate cleanup disabled since it needs code cleanup for 1.8 Midgfard, aborting', MIDCOM_LOG_ERROR);
     return;
     ignore_user_abort();
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'org.openpsa.contacts.duplicates:possible_duplicate');
     $qb->add_order('name', 'ASC');
     $results = @$qb->execute();
     foreach ($results as $param) {
         try {
             $obj = midcom::get('dbfactory')->get_object_by_guid($param->name);
         } catch (midcom_error $e) {
             debug_add("GUID {$param->name} points to nonexistent person, removing possible duplicate mark", MIDCOM_LOG_INFO);
             if (!$param->delete()) {
                 debug_add("Failed to delete parameter {$param->guid}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             }
         }
     }
     debug_add('Done');
     return;
 }
Пример #3
0
 public function get_top(array $args)
 {
     $qb = new midgard_query_builder('fi_openkeidas_diary_activity');
     $qb->set_limit(5);
     $qb->add_order('metadata.score', 'DESC');
     $this->data['sports'] = $qb->execute();
 }
Пример #4
0
 public function get_read(array $args)
 {
     parent::get_read($args);
     $this->data['groups'] = array();
     $this->data['is_challenger'] = $this->is_challenger();
     if ($this->data['is_challenger']) {
         $this->data['groups_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('index', array(), 'fi_openkeidas_groups');
         $this->data['update_url'] = $this->get_url_update();
         $this->data['delete_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_delete', array('challenge' => $this->object->guid), $this->request);
     }
     $activityobject = null;
     if ($this->object->activity) {
         $activityobject = fi_openkeidas_diary_activities::get($this->object->activity);
     }
     $this->object->activityobject = $activityobject;
     $this->data['challenger'] = new fi_openkeidas_groups_group($this->object->challenger);
     $mc = new midgard_collector('fi_openkeidas_diary_challenge_participant', 'challenge', $this->object->id);
     //$mc->add_constraint('metadata.isapproved', '=', true);
     $mc->set_key_property('grp');
     $mc->execute();
     $grp_ids = array_keys($mc->list_keys());
     if (count($grp_ids) == 0) {
         return;
     }
     $qb = new midgard_query_builder('fi_openkeidas_groups_group');
     $qb->add_constraint('id', 'IN', $grp_ids);
     $qb->add_order('metadata.score', 'DESC');
     $this->data['groups'] = array_map(function ($group) use($activityobject) {
         $group->url = midgardmvc_core::get_instance()->dispatcher->generate_url('group_read', array('group' => $group->guid), 'fi_openkeidas_groups');
         $group->activity = fi_openkeidas_diary_logs::group_duration_this_week($group, $activityobject);
         return $group;
     }, $qb->execute());
 }
Пример #5
0
 private function get_snippetdir_children($snippetdir_id)
 {
     // Load children for PROPFIND purposes
     $children = array(array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/", 'title' => $this->object_path, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'));
     // Snippetdirs
     $mc = midgard_snippetdir::new_collector('up', $snippetdir_id);
     $mc->set_key_property('name');
     $mc->add_value_property('description');
     $mc->execute();
     $snippetdirs = $mc->list_keys();
     if (is_array($snippetdirs)) {
         foreach ($snippetdirs as $name => $array) {
             if (empty($name)) {
                 continue;
             }
             $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/{$name}/", 'title' => $name, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection');
         }
     }
     // Snippets
     $qb = new midgard_query_builder('midgard_snippet');
     $qb->add_constraint('up', '=', $snippetdir_id);
     $qb->add_constraint('name', '<>', '');
     $snippets = $qb->execute();
     if (is_array($snippets)) {
         foreach ($snippets as $snippet) {
             $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/{$snippet->name}.php", 'title' => $snippet->name, 'mimetype' => 'text/plain', 'size' => $snippet->metadata->size, 'revised' => $snippet->metadata->revised);
         }
     }
     return $children;
 }
Пример #6
0
 /**
  * Check whether given token has already been used in the database
  *
  * @param string $token
  * @return boolean indicating whether token is free or not (true for free == not present)
  */
 function token_is_free($token, $type = self::SENT)
 {
     $qb = new midgard_query_builder('org_openpsa_campaign_message_receipt');
     $qb->add_constraint('token', '=', $token);
     if ($type) {
         $qb->add_constraint('orgOpenpsaObtype', '=', $type);
     }
     $ret = @$qb->execute();
     if (empty($ret)) {
         return true;
     }
     return false;
 }
Пример #7
0
 /**
  * Seek users with Plazes account settings set
  *
  * @return Array
  */
 function seek_fireeagle_users()
 {
     // TODO: With 1.8 we can query parameters more efficiently
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'net.yahoo.fireeagle');
     $qb->add_constraint('name', '=', 'access_key');
     $accounts = $qb->execute();
     if (count($accounts) > 0) {
         foreach ($accounts as $account_param) {
             $user = new midcom_db_person($account_param->parentguid);
             $this->get_fireeagle_location($user, true);
         }
     }
 }
Пример #8
0
 /**
  * Seek users with Qaiku API key set
  *
  * @return Array
  */
 function seek_qaiku_users()
 {
     // TODO: With 1.8 we can query parameters more efficiently
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'org.routamc.statusmessage:qaiku');
     $qb->add_constraint('name', '=', 'apikey');
     $accounts = $qb->execute();
     if (count($accounts) > 0) {
         foreach ($accounts as $account_param) {
             $user = new midcom_db_person($account_param->parentguid);
             $this->get_qaiku_location($user, true);
         }
     }
 }
Пример #9
0
 /**
  * Seek users with Plazes account settings set
  *
  * @return Array
  */
 function seek_georss_users()
 {
     // TODO: With 1.8 we can query parameters more efficiently
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'org.routamc.positioning:georss');
     $qb->add_constraint('name', '=', 'georss_url');
     $accounts = $qb->execute();
     if (count($accounts) > 0) {
         foreach ($accounts as $account_param) {
             $user = new midcom_db_person($account_param->parentguid);
             $this->get_georss_location($user, true);
         }
     }
 }
Пример #10
0
 /**
  * Seek users with instamapper API key set
  *
  * @return Array
  */
 function seek_instamapper_users()
 {
     // TODO: With 1.8 we can query parameters more efficiently
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'org.routamc.positioning:instamapper');
     $qb->add_constraint('name', '=', 'api_key');
     $accounts = $qb->execute();
     if (count($accounts) > 0) {
         foreach ($accounts as $account_param) {
             try {
                 $user = new midcom_db_person($account_param->parentguid);
                 $this->get_instamapper_location($user, true);
             } catch (midcom_error $e) {
                 continue;
             }
         }
     }
 }
Пример #11
0
 private function create_account(array $ldapuser, array $tokens)
 {
     midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
     $transaction = new midgard_transaction();
     $transaction->begin();
     $qb = new midgard_query_builder('midgard_person');
     $qb->add_constraint('firstname', '=', $ldapuser['firstname']);
     $qb->add_constraint('lastname', '=', $ldapuser['lastname']);
     $persons = $qb->execute();
     if (count($persons) == 0) {
         $person = new midgard_person();
         $person->firstname = $ldapuser['firstname'];
         $person->lastname = $ldapuser['lastname'];
         if (!$person->create()) {
             midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_person for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
             $transaction->rollback();
             midgardmvc_core::get_instance()->authorization->leave_sudo();
             return false;
         }
     } else {
         $person = $persons[0];
     }
     $person->set_parameter('midgardmvc_core_services_authentication_ldap', 'employeenumber', $ldapuser['employeenumber']);
     $user = new midgard_user();
     $user->login = $tokens['login'];
     $user->password = '';
     $user->usertype = 1;
     $user->authtype = 'LDAP';
     $user->active = true;
     $user->set_person($person);
     if (!$user->create()) {
         midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_user for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
         $transaction->rollback();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         return false;
     }
     if (!$transaction->commit()) {
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         return false;
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     return true;
 }
Пример #12
0
 private function get_person_by_name($name)
 {
     // We know the real name, try to match to a Midgard Person
     $name_parts = explode(' ', $_ENV['MIDGARD_ENV_REAL_NAME']);
     if (count($name_parts) < 2) {
         return null;
     }
     $qb = new midgard_query_builder('midgard_person');
     $qb->add_constraint('firstname', '=', $name_parts[0]);
     $qb->add_constraint('lastname', '=', $name_parts[1]);
     $persons = $qb->execute();
     if (count($persons) > 0) {
         return $persons[0];
     }
     $person = new midgard_person();
     $person->firstname = $name_parts[0];
     $person->lastname = $name_parts[1];
     $person->create();
     return $person;
 }
Пример #13
0
 /**
  * Check whether given wikiword is free in given node
  *
  * Returns true if word is free, false if reserved
  */
 public static function node_wikiword_is_free(&$node, $wikiword)
 {
     if (empty($node)) {
         //Invalid node
         debug_add('given node is not valid', MIDCOM_LOG_ERROR);
         return false;
     }
     $wikiword_name = midcom_helper_misc::generate_urlname_from_string($wikiword);
     $qb = new midgard_query_builder('midgard_article');
     $qb->add_constraint('topic', '=', $node[MIDCOM_NAV_OBJECT]->id);
     $qb->add_constraint('name', '=', $wikiword_name);
     $ret = @$qb->execute();
     if (is_array($ret) && count($ret) > 0) {
         //Match found, word is reserved
         debug_add("QB found matches for name '{$wikiword_name}' in topic #{$node[MIDCOM_NAV_OBJECT]->id}, given word '{$wikiword}' is reserved", MIDCOM_LOG_INFO);
         debug_print_r('QB results:', $ret);
         return false;
     }
     return true;
 }
Пример #14
0
/**
 * do a midgard query for username
 * return if username alresdy eixst in db
 * otherwise do an _ldap_search for username
 * if user exists in LDAP then create an account in db
 * if user does not exist then .. give up :)
 */
function ldap_auth_pre_callback($username)
{
    $qb = new midgard_query_builder('midgard_person');
    $qb->add_constraint('username', '=', $username);
    if ($qb->count() > 0) {
        return;
    } else {
        $ldap_user = _ldap_search($username);
        if ($ldap_user) {
            $user = new midgard_person();
            $user->username = $ldap_user['username'];
            $user->firstname = $ldap_user['firstname'];
            $user->email = $ldap_user['email'];
            $user->create();
            // use this parameter to fetch avatars from meego.com
            $user->set_parameter('org.maemo.socialnews', 'employeenumber', $ldap_user['employeenumber']);
        }
    }
    unset($ldap_user);
}
Пример #15
0
 public static function update_sport_and_group(fi_openkeidas_diary_log $log, $params)
 {
     if (!$log->activity) {
         return;
     }
     midgardmvc_core::get_instance()->authorization->enter_sudo('fi_openkeidas_diary');
     $activity = new fi_openkeidas_diary_activity();
     $activity->get_by_id($log->activity);
     $activity->metadata->score++;
     $activity->update();
     $qb = new midgard_query_builder('fi_openkeidas_groups_group_member');
     $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id);
     $qb->add_constraint('metadata.isapproved', '=', true);
     $memberships = $qb->execute();
     foreach ($memberships as $membership) {
         $group = new fi_openkeidas_groups_group($membership->grp);
         $group->metadata->score++;
         $group->update();
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
 }
Пример #16
0
 public function _on_execute()
 {
     debug_add('called!');
     midcom::get('dbclassloader')->load_classes('midcom', 'core_classes.inc', null, true);
     $qb = new midgard_query_builder('midcom_core_login_session_db');
     $qb->add_constraint('timestamp', '<', time() - $GLOBALS['midcom_config']['auth_login_session_timeout']);
     $qb->set_limit(500);
     $result = $qb->execute();
     foreach ($result as $tmp) {
         if (!$tmp->delete()) {
             // Print and log error
             $msg = "Failed to delete login session {$tmp->id}, last Midgard error was: " . midcom_connection::get_error_string();
             $this->print_error($msg);
             debug_add($msg, MIDCOM_LOG_ERROR);
             debug_print_r('Tried to delete this object:', $tmp);
         } else {
             $tmp->purge();
             debug_add("Deleted login session {$tmp->id}.");
         }
     }
 }
Пример #17
0
 /**
  * Match an URL path to a page. Remaining path arguments are stored to argv
  *
  * @param $path URL path
  */
 public function resolve_page($path)
 {
     if (!is_string($path) || substr($path, 0, 1) != '/') {
         throw new InvalidArgumentException('Invalid path provided');
     }
     $temp = trim($path);
     $page = $this->root_page;
     $parent_id = $this->root_page->id;
     // Clean up path
     $path = substr(trim($path), 1);
     if (substr($path, strlen($path) - 1) == '/') {
         $path = substr($path, 0, -1);
     }
     if ($path == '') {
         $this->argv = array();
         $this->set_page($page);
         return;
     }
     $path = explode('/', $path);
     $this->argv = $path;
     foreach ($path as $i => $p) {
         $qb = new midgard_query_builder('midgardmvc_core_node');
         $qb->add_constraint('up', '=', $parent_id);
         $qb->add_constraint('name', '=', $p);
         $res = $qb->execute();
         if (count($res) != 1) {
             break;
         }
         if ($res[0]->templatedir) {
             $this->templatedir_id = $res[0]->templatedir;
         }
         $parent_id = $res[0]->id;
         $temp = substr($temp, 1 + strlen($p));
         $page = $res[0];
         $this->path .= $page->name . '/';
         $this->path_for_page[$page->id] = $this->path;
         array_shift($this->argv);
     }
     $this->set_page($page);
 }
Пример #18
0
function get_image_str_by_counter($max_count, $photostream_prefix)
{
    $img_str = '';
    $image_counter = rand(0, $max_count);
    $image_qb = org_routamc_photostream_photo_dba::new_query_builder();
    $image_qb->set_limit(1);
    $image_qb->set_offset($image_counter - 1);
    $images = $image_qb->execute();
    if (count($images) > 0) {
        $image = $images[0];
        $qb_thumb = new midgard_query_builder('midgard_attachment');
        $qb_thumb->add_constraint('parentguid', '=', $image->guid);
        $qb_thumb->add_constraint('parameter.domain', '=', 'midcom.helper.datamanager2.type.blobs');
        $qb_thumb->add_constraint('parameter.name', '=', 'identifier');
        $qb_thumb->add_constraint('parameter.value', '=', 'thumbnail');
        $thumbs = $qb_thumb->execute();
        if (count($thumbs) > 0) {
            $thumb = $thumbs[0];
            $img_str = '';
            if ($photostream_prefix != '') {
                $img_str = '<a title="' . $image->title . '" href="' . $photostream_prefix . 'photo/' . $image->guid . '/">';
            }
            $img_str .= '<img src="/midcom-serveattachmentguid-' . $thumb->guid . '/' . $thumb->guid . '" border="0" alt="' . $image->title . '" />';
            if ($photostream_prefix != '') {
                $img_str .= '</a>';
            }
            $img_str .= "<br />\n<br />\n";
        }
    }
    return $img_str;
}
Пример #19
0
 public function action_edit($route_id, &$data, $args)
 {
     midgardmvc_core::get_instance()->authorization->require_user();
     $person = midgardmvc_core::get_instance()->authentication->get_person();
     $contact = new net_nemein_avaudu_contact($person->guid);
     // Read current settings from host
     $data['qaiku_apikey'] = $person->get_parameter('net_nemein_avaudu', 'qaiku_apikey');
     // Update things as we go
     if (isset($_POST['qaiku_apikey'])) {
         // Test the API key
         $qaiku_json = @file_get_contents('http://www.qaiku.com/api/statuses/user_timeline.json?apikey=' . $_POST['qaiku_apikey']);
         if (!$qaiku_json) {
             // Qaiku didn't accept the API key
             // TODO: UImessage
             throw new Exception("Invalid Qaiku API key");
         }
         $data['qaiku_apikey'] = $_POST['qaiku_apikey'];
         // Get user info from Qaiku
         $qaikus = json_decode($qaiku_json);
         if (isset($qaikus[0])) {
             $qaiku_user = $qaikus[0]->user;
             $qb = new midgard_query_builder('net_nemein_avaudu_contact');
             $qb->add_constraint('qaikunick', '=', $qaiku_user->screen_name);
             $contacts = $qb->execute();
             if (count($contacts) > 0) {
                 $person->set_parameter('net_nemein_avaudu', 'user', $contacts[0]->guid);
             } else {
                 // Populate "Me" into database
                 $contact->qaikunick = $qaiku_user->screen_name;
                 $contact->name = $qaiku_user->name;
                 $contact->avatar = $qaiku_user->profile_image_url;
                 $contact->qaikuid = $qaiku_user->id;
                 $contact->update();
             }
         }
         // Save the settings
         $person->set_parameter('net_nemein_avaudu', 'qaiku_apikey', $data['qaiku_apikey']);
     }
 }
Пример #20
0
 /**
  * Get document list for requested sequences
  */
 public function get_docs_by_seq(array $args)
 {
     //$this->authenticate();
     // List the requested sequence data
     $qb = new midgard_query_builder('midgard_sequence');
     if (isset($_MIDCOM->dispatcher->get['startkey'])) {
         $qb->add_constraint('id', '>', (int) $_MIDCOM->dispatcher->get['startkey']);
     }
     if (isset($_MIDCOM->dispatcher->get['limit'])) {
         $qb->set_limit((int) $_MIDCOM->dispatcher->get['limit']);
     }
     $qb->add_order('id', 'ASC');
     $transactions = $qb->execute();
     // Prepare the data list
     $this->data['total_rows'] = count($transactions);
     $this->data['offset'] = 0;
     $this->data['rows'] = array();
     // Map the transaction data to what CouchDb protocol wants
     foreach ($transactions as $transaction) {
         $this->data['rows'][] = array('id' => $transaction->objectguid, 'key' => $transaction->id, 'value' => array('rev' => $transaction->revision . '-' . $transaction->metadata->revised->format('U')));
     }
 }
Пример #21
0
 public static function add_challenges_for_group(fi_openkeidas_groups_group $group)
 {
     $mc = new midgard_collector('fi_openkeidas_diary_challenge_participant', 'grp', $group->id);
     //$mc->add_constraint('metadata.isapproved', '=', true);
     $mc->add_constraint('challenge.start', '<=', new DateTime());
     $mc->add_constraint('challenge.enddate', '>', new DateTime());
     $mc->set_key_property('challenge');
     $mc->execute();
     $challenge_ids = array_keys($mc->list_keys());
     if (count($challenge_ids) == 0) {
         return $group;
     }
     $qb = new midgard_query_builder('fi_openkeidas_diary_challenge');
     $qb->add_constraint('id', 'IN', $challenge_ids);
     $group->challenges = array();
     $challenges = $qb->execute();
     foreach ($challenges as $challenge) {
         $challenge->url = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_read', array('challenge' => $challenge->guid), 'fi_openkeidas_diary');
         $group->challenges[] = $challenge;
     }
     return $group;
 }
Пример #22
0
 public function get_graph(array $args)
 {
     midgardmvc_core::get_instance()->authorization->require_user();
     $stat_types = array('bmi', 'weight', 'vo2max');
     $qb = new midgard_query_builder('fi_openkeidas_diary_stat');
     $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id);
     $qb->add_constraint('stat', 'IN', $stat_types);
     $qb->add_order('date', 'ASC');
     $since = new midgard_datetime('6 months ago');
     $qb->add_constraint('date', '>', $since);
     $stats = $qb->execute();
     if (empty($stats)) {
         throw new midgardmvc_exception_notfound("No stats found");
     }
     $dates = array();
     foreach ($stats as $stat) {
         $date = $stat->date->format('d.m.Y');
         if (!isset($dates[$date])) {
             $dates[$date] = array();
         }
         $dates[$date][] = $stat;
     }
     $previous_value = array();
     $this->data['stats'] = array();
     foreach ($dates as $date => $stats) {
         foreach ($stats as $stat) {
             if (!isset($this->data['stats'][$stat->stat])) {
                 $this->data['stats'][$stat->stat] = array();
             }
             $value = round($stat->value, 1);
             $this->data['stats'][$stat->stat][$date] = $value;
             $previous_value[$stat->stat] = $value;
         }
         foreach ($stat_types as $stat_type) {
             if (!isset($this->data['stats'][$stat_type])) {
                 continue;
             }
             if (!isset($this->data['stats'][$stat_type][$date]) && isset($previous_value[$stat_type])) {
                 $this->data['stats'][$stat_type][$date] = $previous_value[$stat_type];
             }
         }
     }
     midgardmvc_core::get_instance()->component->load_library('Graph');
     $graph = new ezcGraphLineChart();
     foreach ($this->data['stats'] as $name => $stats) {
         $graph->data[$this->get_label($name)] = new ezcGraphArrayDataSet($stats);
         $graph->data[$this->get_label($name)]->symbol = ezcGraph::BULLET;
     }
     $graph->driver = new fi_openkeidas_diary_graph_gd();
     $graph->driver->options->imageFormat = IMG_PNG;
     $graph->options->font = midgardmvc_core::get_instance()->configuration->graph_font;
     $graph->legend->position = ezcGraph::BOTTOM;
     $graph->palette = new ezcGraphPaletteEz();
     // render image directly to screen
     $graph->renderToOutput(575, 200);
     // wrap up the request
     midgardmvc_core::get_instance()->dispatcher->end_request();
 }
Пример #23
0
 /**
  * Handler method for listing style elements for the currently used component topic
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  */
 public function _handler_folders($handler_id, array $args, array &$data)
 {
     $this->_group = new midcom_db_group($args[0]);
     midgard_admin_asgard_plugin::bind_to_object($this->_group, $handler_id, $data);
     $qb = new midgard_query_builder('midcom_core_privilege_db');
     $qb->add_constraint('assignee', '=', "group:{$this->_group->guid}");
     $privileges = $qb->execute();
     $data['objects'] = array();
     $data['privileges'] = array();
     foreach ($privileges as $privilege) {
         if (!$privilege->objectguid) {
             // We're only interested in privs applying to objects now, skip
             continue;
         }
         $data['privileges'][] = $privilege->privilegename;
         if (!isset($data['objects'][$privilege->objectguid])) {
             $data['objects'][$privilege->objectguid] = array();
         }
         $data['objects'][$privilege->objectguid][$privilege->privilegename] = $privilege->value;
     }
     $data['view_title'] = sprintf(midcom::get('i18n')->get_string('folders of %s', 'midcom.admin.user'), $this->_group->official);
     midcom::get('head')->set_pagetitle($data['view_title']);
     $this->_update_breadcrumb();
 }
Пример #24
0
 private function prepare_qb(midgardmvc_core_node $node, $limit, $offset = 0)
 {
     $qb = new midgard_query_builder('fi_openkeidas_articles_article');
     $qb->add_constraint('node', 'INTREE', $node->id);
     if (!midgardmvc_ui_create_injector::can_use()) {
         // Regular user, hide unapproved articles
         // TODO: This check should be moved to authentication service when QB has signals
         $qb->add_constraint('metadata.isapproved', '=', true);
     }
     $qb->add_order('metadata.created', 'DESC');
     $qb->set_limit($limit);
     $qb->set_offset($offset);
     return $qb;
 }
Пример #25
0
 public static function within(DateTime $from, DateTime $to, array $users, fi_openkeidas_diary_activity $activity = null)
 {
     if (empty($users)) {
         return array();
     }
     $qb = new midgard_query_builder('fi_openkeidas_diary_log');
     $qb->add_constraint('date', '>', $from);
     $qb->add_constraint('date', '<', $to);
     $qb->add_constraint('person', 'IN', $users);
     if (!is_null($activity)) {
         $qb->add_constraint('activity', '=', $activity->id);
     }
     return $qb->execute();
 }
Пример #26
0
 /**
  * Checks for duplicate memberships returns true for NO duplicate memberships
  */
 private function _check_duplicate_membership()
 {
     $qb = new midgard_query_builder('org_openpsa_campaign_member');
     $qb->add_constraint('person', '=', $this->person);
     $qb->add_constraint('campaign', '=', $this->campaign);
     //For tester membership check only other tester memberships for duplicates, for other memberships check all BUT testers
     if ($this->orgOpenpsaObtype == self::TESTER) {
         $qb->add_constraint('orgOpenpsaObtype', '=', self::TESTER);
     } else {
         $qb->add_constraint('orgOpenpsaObtype', '<>', self::TESTER);
     }
     if ($this->id) {
         $qb->add_constraint('id', '<>', $this->id);
     }
     $ret = $qb->execute();
     if (count($ret) > 0) {
         //We already have a membership with the same campaign and person
         return false;
     }
     return true;
 }
Пример #27
0
 public function _on_execute()
 {
     debug_add('called!');
     $cut_off = mktime(23, 59, 59, date('n'), date('j') - $GLOBALS['midcom_config']['cron_purge_deleted_after'], date('Y'));
     foreach (midcom_connection::get_schema_types() as $mgdschema) {
         if (substr($mgdschema, 0, 2) == '__') {
             continue;
         }
         debug_add("Processing class {$mgdschema}");
         $qb = new midgard_query_builder($mgdschema);
         $qb->add_constraint('metadata.deleted', '<>', 0);
         $qb->add_constraint('metadata.revised', '<', gmdate('Y-m-d H:i:s', $cut_off));
         $qb->include_deleted();
         $qb->set_limit(500);
         $objects = $qb->execute();
         unset($qb);
         if (!is_array($objects)) {
             debug_add("QB failed fatally on class {$mgdschema}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             continue;
         }
         $found = count($objects);
         $purged = 0;
         foreach ($objects as $obj) {
             if (!$obj->purge()) {
                 debug_add("Failed to purge {$mgdschema} {$obj->guid}, deleted: {$obj->metadata->deleted},  revised: {$obj->metadata->revised}. errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
                 debug_print_r('Failed object', $obj);
                 continue;
             }
             $purged++;
         }
         if ($found > 0) {
             debug_add("Found {$found} {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . ", purged {$purged}", MIDCOM_LOG_INFO);
         } else {
             debug_add("No {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . " found");
         }
     }
 }
Пример #28
0
 public function get_object_actions($object)
 {
     $actions = array();
     if (!is_object($object)) {
         return $actions;
     }
     $type = get_class($object);
     $components_to_check = array();
     $libraries_to_check = array();
     if (isset($this->type_action_providers[$type])) {
         // Type-specific actions
         foreach ($this->type_action_providers[$type] as $component) {
             if (isset($this->manifests[$component]['library']) && $this->manifests[$component]['library']) {
                 $libraries_to_check[] = $component;
                 continue;
             }
             $components_to_check[] = $component;
         }
     }
     if (isset($this->type_action_providers['*'])) {
         // Generic actions for any type
         foreach ($this->type_action_providers['*'] as $component) {
             if (isset($this->manifests[$component]['library']) && $this->manifests[$component]['library']) {
                 $libraries_to_check[] = $component;
                 continue;
             }
             $components_to_check[] = $component;
         }
     }
     foreach ($libraries_to_check as $component) {
         $interface = $this->_core->componentloader->load($component);
         $component_actions = $interface->get_object_actions($object);
         $actions = array_merge($actions, $component_actions);
     }
     if (!empty($components_to_check)) {
         $qb = new midgard_query_builder('midgardmvc_core_node');
         $qb->add_constraint('component', 'IN', $components_to_check);
         $folders = $qb->execute();
         foreach ($folders as $folder) {
             $interface = $this->_core->componentloader->load($folder->component, $folder);
             $component_actions = $interface->get_object_actions($object);
             $actions = array_merge($actions, $component_actions);
         }
     }
     return $actions;
 }
Пример #29
0
 public static function is_user($person)
 {
     if (empty($person->guid)) {
         return false;
     }
     if (method_exists('midgard_user', 'login')) {
         // Ratatoskr
         $qb = new midgard_query_builder('midgard_user');
         $qb->add_constraint('person', '=', $person->guid);
         return $qb->count() > 0;
     } else {
         // Ragnaroek
         return $person->username != '';
     }
 }
Пример #30
0
 /**
  * Function deletes login session row from database and
  * cleans away the cookie
  */
 public function logout()
 {
     if ($this->user) {
         $this->user->logout();
     }
     // Remove session cookie from browser
     $this->session_cookie->delete_login_session_cookie();
     // Delete login session from DB
     midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
     $qb = new midgard_query_builder('midgardmvc_core_login_session');
     $qb->add_constraint('guid', '=', $this->session_cookie->get_session_id());
     $res = $qb->execute();
     if (!$res) {
         return false;
     }
     $res[0]->delete();
     $res[0]->purge();
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     // Initialize a fresh session cookie handler
     $this->session_cookie = new midgardmvc_core_services_authentication_cookie();
     return true;
 }