예제 #1
0
파일: undelete.php 프로젝트: nemein/openpsa
 /**
  * Trash view
  *
  * @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_trash($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_admin_user();
     midcom::get('cache')->content->no_cache();
     $data['view_title'] = $this->_l10n->get('trash');
     midcom::get('head')->set_pagetitle($data['view_title']);
     $data['types'] = array();
     foreach (midcom_connection::get_schema_types() as $type) {
         if (substr($type, 0, 2) == '__') {
             continue;
         }
         if (class_exists('midgard_reflector_object')) {
             // In Midgard2 we can have objects that don't
             // have metadata. These should not be shown
             // in trash.
             $ref = new midgard_reflector_object($type);
             if (!$ref->has_metadata_class($type)) {
                 debug_add("{$type} has no metadata, skipping", MIDCOM_LOG_DEBUG);
                 continue;
             }
         }
         $qb = new midgard_query_builder($type);
         $qb->include_deleted();
         $qb->add_constraint('metadata.deleted', '=', true);
         $data['types'][$type] = $qb->count();
     }
     // Set the breadcrumb data
     $this->add_breadcrumb('__mfa/asgard/', $this->_l10n->get('midgard.admin.asgard'));
     $this->add_breadcrumb('__mfa/asgard/trash/', $this->_l10n->get('trash'));
 }
예제 #2
0
 public static function add_members_for_group(fi_openkeidas_groups_group $group)
 {
     $group->url = midgardmvc_core::get_instance()->dispatcher->generate_url('group_read', array('group' => $group->guid), 'fi_openkeidas_groups');
     $member_qb = new midgard_query_builder('fi_openkeidas_groups_group_member');
     $member_qb->add_constraint('grp', '=', $group->id);
     $member_qb->add_constraint('metadata.isapproved', '=', true);
     $group->members = $member_qb->count();
     return $group;
 }
예제 #3
0
 private function is_member()
 {
     $qb = new midgard_query_builder('fi_openkeidas_groups_group_member');
     $qb->add_constraint('grp', '=', $this->object->id);
     $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id);
     $qb->add_constraint('metadata.isapproved', '=', true);
     if ($qb->count() > 0) {
         return true;
     }
     return false;
 }
예제 #4
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);
}
예제 #5
0
 private function _process_photostream_node($node)
 {
     $this->_node = $node;
     $this->_output('Processing photostream node ' . $this->_node->name);
     $photos = $this->_get_photos();
     $this->_output('Found ' . sizeof($photos) . ' photos');
     $i = 0;
     foreach ($photos as $photo) {
         $qb = new midgard_query_builder('org_openpsa_slideshow_image');
         $qb->add_constraint('attachment', '=', $photo->archival);
         if ($qb->count() > 0) {
             $photo->delete();
             continue;
         }
         $slide = new org_openpsa_slideshow_image();
         $slide->title = $photo->title;
         $slide->description = $photo->description;
         $slide->topic = $this->_node->id;
         $slide->attachment = $photo->archival;
         $slide->image = $photo->main;
         $slide->thumbnail = $photo->thumb;
         $slide->position = $i;
         if (!$slide->create()) {
             throw new midcom_error('Could not save new image: ' . midcom_connection::get_error_string());
         }
         $i++;
     }
     if ($i > 0) {
         $this->_node->component = 'org.openpsa.slideshow';
         if (!$this->_node->update()) {
             throw new midcom_error('Could not update node: ' . midcom_connection::get_error_string());
         }
     } else {
         $this->_node->delete();
     }
     $this->_output('Done.');
 }
예제 #6
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 != '';
     }
 }
예제 #7
0
 public function has_child_nodes()
 {
     if (!empty($this->children)) {
         // We already know this from cache
         return true;
     }
     $qb = new midgard_query_builder('midgardmvc_core_node');
     $qb->add_constraint('up', '=', $this->node->id);
     if ($qb->count() > 0) {
         return true;
     }
     return false;
 }
 private function check_email($email)
 {
     $qb = new midgard_query_builder('fi_openkeidas_registration_user');
     $qb->add_constraint('email', '=', $email);
     if ($qb->count() > 0) {
         return false;
     }
     return true;
 }
예제 #9
0
파일: type.php 프로젝트: nemein/openpsa
 private function _prepare_toolbar(&$data)
 {
     if (midcom::get('auth')->can_user_do('midgard:create', null, $this->type)) {
         $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard/object/create/{$this->type}/", MIDCOM_TOOLBAR_LABEL => sprintf(midcom::get('i18n')->get_string('create %s', 'midcom'), midgard_admin_asgard_plugin::get_type_label($this->type)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/' . midcom_helper_reflector_tree::get_create_icon($this->type)));
     }
     if (midcom::get('auth')->admin) {
         $qb = new midgard_query_builder($this->type);
         $qb->include_deleted();
         $qb->add_constraint('metadata.deleted', '=', true);
         $deleted = $qb->count();
         if ($deleted > 0) {
             $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard/trash/{$this->type}/", MIDCOM_TOOLBAR_LABEL => sprintf(midcom::get('i18n')->get_string('%s deleted items', 'midgard.admin.asgard'), $deleted), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash-full.png'));
         } else {
             $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard/trash/{$this->type}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('trash is empty', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png'));
         }
     }
     if ($data['component'] != 'midgard') {
         $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard/components/{$data['component']}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string($data['component'], $data['component']), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/component.png'));
     }
     $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__ais/help/{$data['documentation_component']}/mgdschemas/#{$this->type}", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('type documentation', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_OPTIONS => array('target' => '_blank'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_help-agent.png'));
 }
예제 #10
0
파일: account.php 프로젝트: nemein/openpsa
 private function _is_username_unique()
 {
     if ($this->_midgard2) {
         $qb = new midgard_query_builder('midgard_user');
         $qb->add_constraint('login', '=', $this->get_username());
         $qb->add_constraint('authtype', '=', $GLOBALS['midcom_config']['auth_type']);
     } else {
         $qb = new midgard_query_builder($GLOBALS['midcom_config']['person_class']);
         $qb->add_constraint('username', '=', $this->get_username());
     }
     $qb->add_constraint('guid', '<>', $this->_user->guid);
     return $qb->count() == 0;
 }
예제 #11
0
파일: blobs.php 프로젝트: nemein/openpsa
 /**
  * Deletes an existing attachment.
  *
  * @param string $identifier The identifier of the attachment that should be deleted.
  * @return boolean Indicating success.
  */
 function delete_attachment($identifier)
 {
     if (!array_key_exists($identifier, $this->attachments)) {
         debug_add('Failed to delete the attachment record: The identifier is unknown.', MIDCOM_LOG_INFO);
         return false;
     }
     $attachment = $this->attachments[$identifier];
     // Check that the attachment isn't connected elsewhere via DM2
     $qb = new midgard_query_builder('midgard_parameter');
     $qb->add_constraint('domain', '=', 'midcom.helper.datamanager2.type.blobs');
     $qb->add_constraint('name', '=', "guids_{$this->name}");
     $qb->add_constraint('value', 'LIKE', "%:{$attachment->guid}%");
     if ($qb->count() > 1) {
         debug_add("Attachment {$attachment->guid} is used also elsewhere by DM2, remove only the reference", MIDCOM_LOG_INFO);
     } else {
         if (!$attachment->delete()) {
             debug_add('Failed to delete the attachment record: DBA delete call returned false.', MIDCOM_LOG_INFO);
             return false;
         }
     }
     unset($this->attachments[$identifier]);
     unset($this->attachments_info[$identifier]);
     $this->_sort_attachments();
     $this->_save_attachment_listing();
     return true;
 }
예제 #12
0
 /**
  * Get closest items
  *
  * @param string $class MidCOM DBA class to query
  * @param midgardmvc_helper_location_spot $spot Center position
  * @param integer $limit How many results to return
  * @return Array Array of MidCOM DBA objects sorted by proximity
  */
 static function get_closest($class, midgardmvc_helper_location_spot $spot, $limit, $modifier = 0.15)
 {
     $classname = midgardmvc_helper_location_utils::get_positioning_class($class);
     if ($classname != $class) {
         $direct = false;
     } else {
         $direct = true;
     }
     $qb = new midgard_query_builder($classname);
     if (!$direct) {
         // We're querying a regular DBA object through a location object
         $qb->add_constraint('parentclass', '=', $class);
     }
     static $rounds = 0;
     $rounds++;
     $from['latitude'] = $spot->latitude + $modifier;
     if ($from['latitude'] > 90) {
         $from['latitude'] = 90;
     }
     $from['longitude'] = $spot->longitude - $modifier;
     if ($from['longitude'] < -180) {
         $from['longitude'] = -180;
     }
     $to['latitude'] = $spot->latitude - $modifier;
     if ($to['latitude'] < -90) {
         $to['latitude'] = -90;
     }
     $to['longitude'] = $spot->longitude + $modifier;
     if ($to['longitude'] > 180) {
         $to['longitude'] = 180;
     }
     if (!isset($current_locale)) {
         $current_locale = setlocale(LC_NUMERIC, '0');
         setlocale(LC_NUMERIC, 'C');
     }
     $qb->begin_group('AND');
     $qb->add_constraint('latitude', '<', (double) $from['latitude']);
     $qb->add_constraint('latitude', '>', (double) $to['latitude']);
     $qb->end_group();
     $qb->begin_group('AND');
     $qb->add_constraint('longitude', '>', (double) $from['longitude']);
     $qb->add_constraint('longitude', '<', (double) $to['longitude']);
     $qb->end_group();
     $result_count = $qb->count();
     //echo "<br />Round {$rounds}, lat1 {$from['latitude']} lon1 {$from['longitude']}, lat2 {$to['latitude']} lon2 {$to['longitude']}: {$result_count} results\n";
     if ($result_count < $limit) {
         if ($from['latitude'] == 90 && $from['longitude'] == -180 && $to['latitude'] == -90 && $to['longitude'] == 180) {
             // We've queried the entire globe so we return whatever we got
             $results = $qb->execute();
             $closest = array();
             foreach ($results as $result) {
                 $result_spot = new midgardmvc_helper_location_spot($result);
                 $distance = sprintf("%05d", round(midgardmvc_helper_location_utils::get_distance($spot, $result_spot)));
                 if (!$direct) {
                     // Instantiate the real object as the result
                     $result = new $class($result->parent);
                     $result->spot = $result_spot;
                     $result->latitude = $result_spot->latitude;
                     $result->longitude = $result_spot->longitude;
                 }
                 $closest[$distance . $result->guid] = $result;
             }
             ksort($closest);
             reset($closest);
             return $closest;
         }
         $modifier = $modifier * 1.05;
         setlocale(LC_NUMERIC, $current_locale);
         return midgardmvc_helper_location_utils::get_closest($class, $spot, $limit, $modifier);
     }
     $results = $qb->execute();
     $closest = array();
     foreach ($results as $result) {
         $result_spot = new midgardmvc_helper_location_spot($result);
         $distance = sprintf("%05d", round(midgardmvc_helper_location_utils::get_distance($spot, $result_spot)));
         if (!$direct) {
             // Instantiate the real object as the result
             $result = new $class($result->parent);
             $result->spot = $result_spot;
             $result->latitude = $result_spot->latitude;
             $result->longitude = $result_spot->longitude;
         }
         $closest[$distance . $result->guid] = $result;
     }
     ksort($closest);
     reset($closest);
     while (count($closest) > $limit) {
         array_pop($closest);
     }
     setlocale(LC_NUMERIC, $current_locale);
     return $closest;
 }
예제 #13
0
파일: message.php 프로젝트: nemein/openpsa
 /**
  * Returns the count of matching members and message receipts
  */
 function send_mms_status()
 {
     $qb_mem = new midgard_query_builder('org_openpsa_campaign_member');
     $qb_mem->add_constraint('person.handphone', '<>', '');
     $this->_qb_common_constaints($qb_mem);
     $valid_members = $qb_mem->count();
     $qb_receipts = new midgard_query_builder('org_openpsa_campaign_message_receipt');
     $qb_receipts->add_constraint('message', '=', $this->id);
     $qb_receipts->add_constraint('orgOpenpsaObtype', '=', org_openpsa_directmarketing_campaign_messagereceipt_dba::SENT);
     $send_receipts = $qb_receipts->count();
     return array($valid_members, $send_receipts);
 }