Esempio n. 1
0
 /**
  * @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)
 {
     midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface');
     $data['controller'] = $this->get_controller('nullstorage');
     // Check if we get the person
     $this->_person = new midcom_db_person($args[0]);
     $this->_person->require_do('midgard:update');
     $this->_account = new midcom_core_account($this->_person);
     if ($this->_account->get_username()) {
         throw new midcom_error('Given user already has an account');
     }
     switch ($data['controller']->process_form()) {
         case 'save':
             $this->_master->create_account($this->_person, $data["controller"]->formmanager);
         case 'cancel':
             return new midcom_response_relocate('view/' . $this->_person->guid . '/');
     }
     if ($this->_person->email) {
         // Email address (first part) is the default username
         $this->_request_data['default_username'] = preg_replace('/@.*/', '', $this->_person->email);
     } else {
         // Otherwise use cleaned up firstname.lastname
         $this->_request_data['default_username'] = midcom_helper_misc::generate_urlname_from_string($this->_person->firstname) . '.' . midcom_helper_misc::generate_urlname_from_string($this->_person->lastname);
     }
     midcom::get('head')->set_pagetitle("{$this->_person->firstname} {$this->_person->lastname}");
     $this->_prepare_request_data();
     $this->_update_breadcrumb_line('create account');
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this);
 }
Esempio n. 2
0
 private function initialize_site_structure()
 {
     $nodes = array();
     foreach ($this->components as $component) {
         $nodes[$component] = midcom_helper_misc::find_node_by_component($component);
     }
     if (empty($nodes)) {
         return;
     }
     foreach ($nodes as $component => $node) {
         $parts = explode('.', $component);
         $last = array_pop($parts);
         $node_guid = 'false';
         $node_full_url = 'false';
         $node_relative_url = 'false';
         if (is_array($node)) {
             $node_guid = "'" . $node[MIDCOM_NAV_OBJECT]->guid . "'";
             $node_full_url = "'" . $node[MIDCOM_NAV_FULLURL] . "'";
             $node_relative_url = "'" . $node[MIDCOM_NAV_RELATIVEURL] . "'";
         }
         $this->set_config_value($last . '_guid', $node_guid);
         $this->set_config_value($last . '_full_url', $node_full_url);
         $this->set_config_value($last . '_relative_url', $node_relative_url);
     }
     midcom::get('auth')->request_sudo('org.openpsa.core');
     $this->snippet->update();
     midcom::get('auth')->drop_sudo();
     midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.core'), $this->_l10n->get('site structure cache created'), 'info');
 }
Esempio n. 3
0
 public function get_row(midcom_core_dbaobject $document)
 {
     $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
     $entry = array();
     $entry['id'] = $document->id;
     $entry['index_title'] = $document->title;
     $entry['index_filesize'] = 0;
     $entry['filesize'] = '';
     $entry['mimetype'] = '';
     $icon = MIDCOM_STATIC_URL . '/stock-icons/mime/gnome-text-blank.png';
     $alt = '';
     $att = $document->load_attachment();
     if ($att) {
         $icon = midcom_helper_misc::get_mime_icon($att->mimetype);
         $alt = $att->name;
         $stats = $att->stat();
         $entry['index_filesize'] = $stats[7];
         $entry['filesize'] = midcom_helper_misc::filesize_to_string($stats[7]);
         $entry['mimetype'] = org_openpsa_documents_document_dba::get_file_type($att->mimetype);
     }
     $title = '<a class="tab_escape" href="' . $prefix . 'document/' . $document->guid . '/"><img src="' . $icon . '"';
     $title .= 'alt="' . $alt . '" style="border: 0px; height: 16px; vertical-align: middle" /> ' . $document->title . '</a>';
     $entry['title'] = $title;
     $entry['created'] = strftime('%Y-%m-%d %X', $document->metadata->created);
     $entry['index_author'] = '';
     $entry['author'] = '';
     if ($document->author) {
         $author = org_openpsa_contacts_person_dba::get_cached($document->author);
         $entry['index_author'] = $author->rname;
         $author_card = org_openpsa_widgets_contact::get($author->guid);
         $entry['author'] = $author_card->show_inline();
     }
     return $entry;
 }
Esempio n. 4
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 private function _create_product($title, $productgroup)
 {
     $product = new org_openpsa_products_product_dba();
     $product->productGroup = $productgroup;
     $product->title = $title;
     if (!$product->create()) {
         debug_print_r('We operated on this object:', $product);
         return null;
     }
     // Generate URL name
     if ($product->code == '') {
         $product->code = midcom_helper_misc::generate_urlname_from_string($product->title);
         $tries = 0;
         $maxtries = 999;
         while (!$product->update() && $tries < $maxtries) {
             $product->code = midcom_helper_misc::generate_urlname_from_string($product->title);
             if ($tries > 0) {
                 // Append an integer if products with same name exist
                 $product->code .= sprintf("-%03d", $tries);
             }
             $tries++;
         }
     }
     $product->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_products_schema'));
     return $product;
 }
Esempio n. 5
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 private function _create_article($title)
 {
     $author = midcom::get('auth')->user->get_storage();
     $article = new midcom_db_article();
     $article->topic = $this->_content_topic->id;
     $article->title = $title;
     //Figure out author
     $article->author = $author->id;
     if (!$article->create()) {
         debug_print_r('We operated on this object:', $article);
         return null;
     }
     // Generate URL name
     if ($article->name == '') {
         $article->name = midcom_helper_misc::generate_urlname_from_string($article->title);
         $tries = 0;
         $maxtries = 999;
         while (!$article->update() && $tries < $maxtries) {
             $article->name = midcom_helper_misc::generate_urlname_from_string($article->title);
             if ($tries > 0) {
                 // Append an integer if articles with same name exist
                 $article->name .= sprintf("-%03d", $tries);
             }
             $tries++;
         }
     }
     $article->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_metaweblog_schema'));
     return $article;
 }
Esempio n. 6
0
 public function __construct($target_node, $target_object, $new_wikipage = null)
 {
     parent::__construct();
     $this->target_node = $target_node;
     $this->target = midcom::get('dbfactory')->get_object_by_guid($target_object);
     $this->wiki = midcom_helper_misc::find_node_by_component('net.nemein.wiki');
     if ($new_wikipage) {
         $this->new_wikipage = rawurlencode(str_replace('/', '-', $new_wikipage));
     }
 }
function midgard_admin_asgard_trash_type_show($object, $indent = 0, $prefix = '', $enable_undelete = true)
{
    static $persons = array();
    static $shown = array();
    static $url_prefix = '';
    if (!$url_prefix) {
        $url_prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
    }
    if (isset($shown[$object->guid])) {
        return;
    }
    if (!isset($persons[$object->metadata->revisor])) {
        $persons[$object->metadata->revisor] = midcom::get('auth')->get_user($object->metadata->revisor);
    }
    $reflector = midcom_helper_reflector_tree::get($object);
    $icon = $reflector->get_object_icon($object);
    echo "{$prefix}<tr>\n";
    $disabled = '';
    if (!$enable_undelete) {
        $disabled = ' disabled="disabled"';
    }
    $object_label = $reflector->get_object_label($object);
    if (empty($object_label)) {
        $object_label = $object->guid;
    }
    echo "{$prefix}    <td class=\"checkbox\"><input type=\"checkbox\" name=\"undelete[]\"{$disabled} value=\"{$object->guid}\" id=\"guid_{$object->guid}\" /></td>\n";
    echo "{$prefix}    <td class=\"label\" style=\"padding-left: {$indent}px\"><label for=\"guid_{$object->guid}\">{$icon}" . $object_label . "</label></td>\n";
    echo "{$prefix}    <td class=\"nowrap\">" . strftime('%x %X', strtotime($object->metadata->revised)) . "</td>\n";
    if (isset($persons[$object->metadata->revisor]->guid)) {
        echo "{$prefix}    <td><a href=\"{$url_prefix}__mfa/asgard/object/view/{$persons[$object->metadata->revisor]->guid}/\">{$persons[$object->metadata->revisor]->name}</a></td>\n";
    } else {
        echo "{$prefix}    <td>&nbsp;</td>\n";
    }
    echo "{$prefix}    <td>" . midcom_helper_misc::filesize_to_string($object->metadata->size) . "</td>\n";
    echo "{$prefix}</tr>\n";
    $child_types = midcom_helper_reflector_tree::get_child_objects($object, true);
    if (is_array($child_types) && count($child_types) > 0) {
        $child_indent = $indent + 20;
        echo "{$prefix}<tbody class=\"children\">\n";
        foreach ($child_types as $type => $children) {
            if (count($children) < 10 || isset($_GET['show_children'][$object->guid][$type])) {
                foreach ($children as $child) {
                    midgard_admin_asgard_trash_type_show($child, $child_indent, "{$prefix}    ", false);
                }
            } else {
                echo "{$prefix}    <tr>\n";
                echo "{$prefix}        <td class=\"label\" style=\"padding-left: {$child_indent}px\" colspan=\"5\"><a href=\"?show_children[{$object->guid}][{$type}]=1\">" . sprintf(midcom::get('i18n')->get_string('show %s %s children', 'midgard.admin.asgard'), count($children), midgard_admin_asgard_plugin::get_type_label($type)) . "</a></td>\n";
                echo "{$prefix}    </tr>\n";
            }
        }
        echo "{$prefix}</tbody>\n";
    }
    $shown[$object->guid] = true;
}
Esempio n. 8
0
 /**
  * Adds a simple single-line text form element at this time.
  */
 function add_elements_to_form($attributes)
 {
     $attributes = array_merge($attributes, array('rows' => $this->height, 'cols' => $this->width, 'class' => "codemirror {$this->language}", 'id' => "{$this->_namespace}{$this->name}"));
     if (!$this->enabled) {
         $attributes['class'] = 'longtext';
     }
     $this->_form->addElement('textarea', $this->name, $this->_translate($this->_field['title']), $attributes);
     $this->_form->applyFilter($this->name, 'trim');
     $config = midcom_helper_misc::get_snippet_content_graceful($this->_config->get('codemirror_config_snippet'));
     $config = str_replace('{$id}', $attributes['id'], $config);
     $config = str_replace('{$read_only}', 'false', $config);
     midcom::get('head')->add_jquery_state_script($config);
 }
Esempio n. 9
0
 /**
  * Adds a simple single-line text form element at this time.
  */
 function add_elements_to_form($attributes)
 {
     $elements = array();
     $attributes = array_merge($attributes, array('class' => 'captcha', 'id' => "{$this->_namespace}{$this->name}"));
     $static_html = recaptcha_get_html($this->_public_key);
     $static_html = midcom_helper_misc::get_snippet_content_graceful('/sitegroup-config/midcom.helper.datamanager2/recaptcha') . $static_html;
     $this->_element = HTML_QuickForm::createElement('static', "{$this->name}_captcha", '', $static_html);
     $elements[] = $this->_element;
     $elements[] = HTML_QuickForm::createElement('hidden', $this->name, '', $attributes);
     $this->_form->applyFilter($this->name, 'trim');
     $this->_form->addGroup($elements, "{$this->name}_group", $this->_translate($this->_field['title']), '<br />', false);
     $this->_form->addFormRule(array(&$this, 'validate'));
 }
Esempio n. 10
0
 /**
  * This is what Datamanager calls to actually create a directory
  */
 public function &dm2_create_callback(&$datamanager)
 {
     $topic = new org_openpsa_documents_directory();
     $topic->up = $this->_request_data['directory']->id;
     $topic->component = 'org.openpsa.documents';
     // Set the name by default
     $topic->name = midcom_helper_misc::generate_urlname_from_string($_POST['extra']);
     if (!$topic->create()) {
         debug_print_r('We operated on this object:', $topic);
         throw new midcom_error("Failed to create a new topic, cannot continue. Error: " . midcom_connection::get_error_string());
     }
     $this->_request_data['directory'] = new org_openpsa_documents_directory($topic->id);
     return $topic;
 }
Esempio n. 11
0
 function read_structure()
 {
     // Generate a safe name for the structure
     $structure_name = midcom_helper_misc::generate_urlname_from_string(midcom::get()->get_page_prefix());
     // Prepare structure
     $structure = array();
     $structure[$structure_name] = array();
     $structure[$structure_name]['name'] = $structure_name;
     $structure[$structure_name]['title'] = $GLOBALS['midcom_config']['midcom_site_title'];
     // Read the topic data
     $root_node = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC);
     $structure[$structure_name]['root'] = $this->read_node($root_node);
     file_put_contents("{$this->root_dir}{$structure_name}.inc", $this->_draw_array($structure));
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 public function _on_creating()
 {
     if ($this->title == '' || !$this->topic) {
         // We must have wikiword and topic at this stage
         return false;
     }
     // Check for duplicates
     $qb = net_nemein_wiki_wikipage::new_query_builder();
     $qb->add_constraint('topic', '=', $this->topic);
     $qb->add_constraint('title', '=', $this->title);
     $result = $qb->execute();
     if (count($result) > 0) {
         midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS);
         return false;
     }
     // Generate URL-clean name
     if ($this->name != 'index') {
         $this->name = midcom_helper_misc::generate_urlname_from_string($this->title);
     }
     return true;
 }
Esempio n. 14
0
 private function _populate_toolbar()
 {
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "group/edit/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get("edit"), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_group->can_do('midgard:update'), MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "group/create/organization/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create suborganization'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_people-new.png', MIDCOM_TOOLBAR_ENABLED => $this->_group->can_do('midgard:update')));
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "group/create/group/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create subgroup'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_people-new.png', MIDCOM_TOOLBAR_ENABLED => $this->_group->can_do('midgard:update')));
     if (midcom::get('auth')->can_user_do('midgard:create', null, 'org_openpsa_contacts_person_dba') && $this->_group->can_do('midgard:create')) {
         $allow_person_create = true;
     } else {
         $allow_person_create = false;
     }
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/create/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create person'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_person-new.png', MIDCOM_TOOLBAR_ENABLED => $allow_person_create));
     $siteconfig = org_openpsa_core_siteconfig::get_instance();
     $user_url = $siteconfig->get_node_full_url('org.openpsa.user');
     if ($user_url && 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 . "group/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('user management', 'org.openpsa.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png'));
     }
     $cal_node = midcom_helper_misc::find_node_by_component('org.openpsa.calendar');
     if (!empty($cal_node)) {
         //TODO: Check for privileges somehow
         $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "#", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create event'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_new-event.png', MIDCOM_TOOLBAR_OPTIONS => array('rel' => 'directlink', 'onclick' => org_openpsa_calendar_interface::calendar_newevent_js($cal_node, false, $this->_group->guid))));
     }
 }
Esempio n. 15
0
 function save_archival_image()
 {
     if ($this->do_not_save_archival) {
         return true;
     }
     $identifier = 'archival';
     return $this->add_attachment($identifier, "{$identifier}_{$this->_filename}", $this->title, midcom_helper_misc::get_mimetype($this->_original_tmpname), $this->_original_tmpname, false);
 }
Esempio n. 16
0
<?php

$view = $data['document_dm'];
$att = $data['document_attachment'];
$document_type = midcom_helper_misc::filesize_to_string($att['filesize']) . ' ' . org_openpsa_documents_document_dba::get_file_type($att['mimetype']);
$nap = new midcom_helper_nav();
$node = $nap->get_node($nap->get_current_node());
$score = round($data['document_search']->score * 100);
$url = $data['document_search']->topic_url . 'document/' . $data['document']->guid . '/';
// MIME type
$icon = MIDCOM_STATIC_URL . '/stock-icons/mime/gnome-text-blank.png';
if ($att) {
    $icon = midcom_helper_misc::get_mime_icon($att['mimetype']);
}
?>
<dt><a href="&(url);"><?php 
echo $view['title'];
?>
</a></dt>
<dd>
<?php 
if ($icon) {
    ?>
    <div class="icon"><a style="text-decoration: none;" href="&(node[MIDCOM_NAV_FULLURL]);document/<?php 
    echo $data['document']->guid;
    ?>
/"><img src="&(icon);" <?php 
    if ($view['document']) {
        echo 'title="' . $document_type . '" ';
    }
    ?>
Esempio n. 17
0
 /**
  * Load a language database
  *
  * - Leading and trailing whitespace will be eliminated
  */
 private function _load_language($lang)
 {
     $this->_stringdb[$lang] = array();
     $filename = "{$this->_library_filename}.{$lang}.txt";
     if ($GLOBALS['midcom_config']['cache_module_memcache_backend'] != 'flatfile') {
         $stringtable = midcom::get('cache')->memcache->get('L10N', $filename);
         if (is_array($stringtable)) {
             $this->_stringdb[$lang] = $stringtable;
             return;
         }
     }
     if (!empty(midcom::get('componentloader')->manifests[$this->_component_name]->extends)) {
         $parent_l10n = new self(midcom::get('componentloader')->manifests[$this->_component_name]->extends, 'default');
         $this->_stringdb[$lang] = $parent_l10n->get_stringdb($lang);
     }
     if (!file_exists($filename)) {
         return;
     }
     $data = file($filename);
     // get site-specific l10n
     $component_locale = midcom_helper_misc::get_snippet_content_graceful($GLOBALS['midcom_config']['midcom_sgconfig_basedir'] . "/" . $this->_component_name . "/l10n/" . $lang);
     if (!empty($component_locale)) {
         $data = array_merge($data, explode("\n", $component_locale));
     }
     // Parse the Array
     $stringtable = array();
     $version = '';
     $language = '';
     $instring = false;
     $string_data = '';
     $string_key = '';
     foreach ($data as $line => $string) {
         // Kill any excess whitespace first.
         $string = trim($string);
         if (!$instring) {
             // outside of a string value
             if ($string == '') {
                 // Do nothing
             } else {
                 if (substr($string, 0, 3) == '---') {
                     // this is a command
                     if (strlen($string) < 4) {
                         $line++;
                         // Array is 0-indexed
                         throw new midcom_error("L10n DB SYNTAX ERROR: An incorrect command was detected at {$filename}:{$line}");
                     }
                     $pos = strpos($string, ' ');
                     if ($pos === false) {
                         $command = substr($string, 3);
                     }
                     $command = substr($string, 3, $pos - 3);
                     switch ($command) {
                         case '#':
                             // Skip
                             break;
                         case 'VERSION':
                             if ($version != '') {
                                 $line++;
                                 // Array is 0-indexed
                                 throw new midcom_error("L10n DB SYNTAX ERROR: A second VERSION tag has been detected at {$filename}:{$line}");
                             }
                             $version = substr($string, 11);
                             break;
                         case 'LANGUAGE':
                             if ($language != '') {
                                 $line++;
                                 // Array is 0-indexed
                                 throw new midcom_error("L10n DB SYNTAX ERROR: A second LANGUAGE tag has been detected at {$filename}:{$line}");
                             }
                             $language = substr($string, 12);
                             break;
                         case 'STRING':
                             $string_data = '';
                             $string_key = substr($string, 10);
                             $instring = true;
                             break;
                         default:
                             $line++;
                             // Array is 0-indexed
                             throw new midcom_error("L10n DB SYNTAX ERROR: Unknown command '{$command}' at {$filename}:{$line}");
                     }
                 } else {
                     $line++;
                     // Array is 0-indexed
                     throw new midcom_error("L10n DB SYNTAX ERROR: Invalid line at {$filename}:{$line}");
                 }
             }
         } else {
             // Within a string value
             if ($string == '---STRINGEND') {
                 $instring = false;
                 $stringtable[$string_key] = $string_data;
             } else {
                 if ($string_data == '') {
                     $string_data .= $string;
                 } else {
                     $string_data .= "\n{$string}";
                 }
             }
         }
     }
     if ($instring) {
         throw new midcom_error("L10n DB SYNTAX ERROR: String constant exceeds end of file.");
     }
     if (version_compare($version, $this->_version, "<")) {
         throw new midcom_error("L10n DB ERROR: File format version of {$filename} is too old, no update available at the moment.");
     }
     if ($lang != $language) {
         throw new midcom_error("L10n DB ERROR: The DB language version {$language} did not match the requested {$lang}.");
     }
     ksort($stringtable, SORT_STRING);
     $this->_stringdb[$lang] = array_merge($this->_stringdb[$lang], $stringtable);
     if ($GLOBALS['midcom_config']['cache_module_memcache_backend'] != 'flatfile') {
         midcom::get('cache')->memcache->put('L10N', $filename, $this->_stringdb[$lang]);
     }
 }
Esempio n. 18
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_article = new midcom_db_article();
     $this->_article->topic = $this->_content_topic->id;
     if (!$this->_article->create()) {
         debug_print_r('We operated on this object:', $this->_article);
         throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     // Callback possibility
     if ($this->_config->get('callback_function')) {
         if ($this->_config->get('callback_snippet')) {
             // mgd_include_snippet($this->_config->get('callback_snippet'));
             $eval = midcom_helper_misc::get_snippet_content($this->_config->get('callback_snippet'));
             if ($eval) {
                 eval($eval);
             }
         }
         $callback = $this->_config->get('callback_function');
         $callback($this->_article, $this->_content_topic);
     }
     return $this->_article;
 }
Esempio n. 19
0
                <td class="numeric"><?php 
echo $total;
?>
</td>
                <td>&nbsp;</td>
                <td class="numeric"><?php 
echo round($total / ($report['receipt_data']['sent'] - $report['receipt_data']['bounced']) * 100, 2);
?>
</td>
            </tr>
    </table>
    <input type="submit" class="button create_campaign" value="<?php 
echo $l10n->get('create campaign from link');
?>
"/>
</form>
<?php 
$reports_node = midcom_helper_misc::find_node_by_component('org.openpsa.reports');
if (!empty($reports_node)) {
    $reports_prefix = $reports_node[MIDCOM_NAV_FULLURL];
    $filename = 'org_openpsa_directmarketing_' . date('Ymd_Hi');
    ?>
<form method="post" action="&(reports_prefix);csv/&(filename);.csv" onSubmit="return table2csv('org_openpsa_directmarketing_messagelinks&(form_suffix);');">
    <input type="hidden" id="csvdata" name="org_openpsa_reports_csv" value="" />
    <input class="button" type="submit" value="<?php 
    echo midcom::get('i18n')->get_string('download as CSV', 'org.openpsa.core');
    ?>
" />
</form>
    <?php 
}
Esempio n. 20
0
 /**
  * Copy an object
  *
  * @param mixed &$source     MgdSchema object for reading the parameters
  * @param mixed &$parent      MgdSchema parent object
  * @param array $defaults
  * @return boolean Indicating success
  */
 public function copy_object(&$source, &$parent = null, $defaults = array())
 {
     // Resolve the source object
     self::resolve_object($source);
     // Duplicate the object
     $class_name = get_class($source);
     $target = new $class_name();
     $properties = $this->get_object_properties($source);
     // Copy the object properties
     foreach ($properties as $property) {
         // Skip certain fields
         if (preg_match('/^(_|metadata|guid|id)/', $property)) {
             continue;
         }
         $target->{$property} = $source->{$property};
     }
     // Override requested root object properties
     if (isset($this->target->guid) && $target->guid === $this->target->guid) {
         foreach ($this->root_object_values as $name => $value) {
             $target->{$name} = $value;
         }
     }
     // Override with defaults
     if ($defaults) {
         foreach ($defaults as $name => $value) {
             $target->{$name} = $value;
         }
     }
     $parent_property = $this->get_parent_property($source);
     // Copy the link to parent
     if ($parent) {
         self::resolve_object($parent);
         if (!$parent || !$parent->guid) {
             return false;
         }
         // @TODO: Is there a sure way to determine if the parent is
         // GUID or is it ID? If so, please change it here.
         if (is_string($source->{$parent_property})) {
             $parent_key = 'guid';
         } else {
             $parent_key = 'id';
         }
         $target->{$parent_property} = $parent->{$parent_key};
     } else {
         if (is_string($source->{$parent_property})) {
             $target->{$parent_property} = '';
         } else {
             $target->{$parent_property} = 0;
         }
     }
     $name_property = midcom_helper_reflector::get_name_property($target);
     $resolver = new midcom_helper_reflector_nameresolver($target);
     if (!empty($name_property) && !$resolver->name_is_safe_or_empty($name_property)) {
         debug_add('Source object ' . get_class($source) . " {$source->guid} has unsafe name, rewriting to safe form for the target", MIDCOM_LOG_WARN);
         $name_property = midcom_helper_reflector::get_name_property($target);
         if (empty($name_property)) {
             $this->errors[] = sprintf($this->_l10n->get('cannot fix unsafe name for source object %s, skipping'), get_class($source) . " {$source->guid}");
             return false;
         }
         $name_parts = explode('.', $target->{$name_property}, 2);
         if (isset($name_parts[1])) {
             $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($name_parts[0]) . ".{$name_parts[1]}";
             // Doublecheck safety and fall back if needed
             if (!$resolver->name_is_safe_or_empty()) {
                 $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($target->{$name_property});
             }
         } else {
             $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($target->{$name_property});
         }
         unset($name_parts, $name_property);
     }
     if ($this->allow_name_catenate && $name_property) {
         $name = $resolver->generate_unique_name();
         if ($name !== $target->{$name_property}) {
             $target->{$name_property} = $name;
         }
     }
     // This needs to be here, otherwise it will be overridden
     $target->allow_name_catenate = true;
     if (!$target->create()) {
         $this->errors[] = $this->_l10n->get('failed to create object: ' . mgd_errstr());
         return false;
     }
     // Store for later use - if ever needed
     $this->new_objects[] = $target;
     unset($name_property);
     // Copy parameters
     if (!$this->copy_parameters($source, $target) && $this->halt_on_errors) {
         $this->errors[] = $this->_l10n->get('failed to copy parameters');
         return false;
     }
     // Copy metadata
     if (!$this->copy_metadata($source, $target) && $this->halt_on_errors) {
         $this->errors[] = $this->_l10n->get('failed to copy metadata');
         return false;
     }
     // Copy attachments
     if (!$this->copy_attachments($source, $target) && $this->halt_on_errors) {
         $this->errors[] = $this->_l10n->get('failed to copy attachments');
         return false;
     }
     // Copy privileges
     if (!$this->copy_privileges($source, $target) && $this->halt_on_errors) {
         $this->errors[] = $this->_l10n->get('failed to copy privileges');
         return false;
     }
     return $target;
 }
Esempio n. 21
0
 /**
  * Make sure our name is nice and clean
  *
  * @see http://trac.midgard-project.org/ticket/809
  */
 public function _on_validate()
 {
     $schema = $this->storage->_schema->fields[$this->name];
     $copy = $this->_copy_object($this->storage->object);
     $property = $schema['storage']['location'];
     $resolver = new midcom_helper_reflector_nameresolver($copy);
     if (empty($this->value)) {
         if (isset($this->_datamanager->types[$this->title_field]) && $this->_datamanager->types[$this->title_field]->value) {
             $copy->{$property} = midcom_helper_misc::generate_urlname_from_string($this->_datamanager->types[$this->title_field]->value);
             $this->value = $resolver->generate_unique_name();
         }
     }
     $copy->{$property} = $this->value;
     if (!$resolver->name_is_safe($property)) {
         $this->validation_error = sprintf($this->_l10n->get('type urlname: name is not "URL-safe", try "%s"'), midcom_helper_misc::generate_urlname_from_string($this->value));
         return false;
     }
     if (!$this->allow_unclean && !$resolver->name_is_clean($property)) {
         $this->validation_error = sprintf($this->_l10n->get('type urlname: name is not "clean", try "%s"'), midcom_helper_misc::generate_urlname_from_string($this->value));
         return false;
     }
     if (!$resolver->name_is_unique()) {
         $new_name = $resolver->generate_unique_name();
         if ($this->allow_catenate) {
             // If allowed to, silently use the generated name
             $this->value = $new_name;
             $this->_orig_value = $new_name;
             $copy->{$property} = $this->value;
         } else {
             $this->validation_error = sprintf($this->_l10n->get('type urlname: name is already taken, try "%s"'), $new_name);
             return false;
         }
     }
     return true;
 }
Esempio n. 22
0
    $class = 'document ' . $document->get_class();
    $link_html = "<![CDATA[";
    $link_html .= "<a href='" . $prefix . $path . "document/" . $document->guid . "/' class='" . $class . "'>";
    $link_html .= "<img class='document_icon' src='" . $icon . "' />";
    $link_html .= "<span>" . $document->title . "</span></a>";
    $link_html .= "]]>";
    echo "<cell>" . $link_html . "</cell>";
    echo "<cell> " . $download_url . "</cell>";
    //set contact-widget
    if (empty($document->author)) {
        $author = org_openpsa_widgets_contact::get($document->metadata->creator);
    } else {
        $author = org_openpsa_widgets_contact::get($document->author);
    }
    // creator_index, creator-vcard & revised date
    echo "<cell>" . $author->contact_details['lastname'] . ", " . $author->contact_details['firstname'] . "</cell>";
    echo "<cell><![CDATA[<span class='jqgrid_person'>" . $author->show_inline() . "</span>]]></cell>";
    echo "<cell> " . $document->metadata->revised . "</cell>";
    echo "<cell><![CDATA[<span class='jqgrid_date'>" . date("d.m.Y H:m", $document->metadata->revised) . "</span>]]></cell>";
    //filesize-index & modified file_size
    echo "<cell>" . $file_size . "</cell>";
    echo "<cell><![CDATA[<span class='jqgrid_size'>" . midcom_helper_misc::filesize_to_string($file_size) . "</span>]]></cell>";
    //level & parent of document
    echo "<cell>" . $level . "</cell>";
    echo "<cell>" . $parent . "</cell>";
    // leaf = true , expanded = false
    echo "<cell>true</cell>";
    echo "<cell>false</cell>";
    echo "</row>";
}
echo "</rows>";
Esempio n. 23
0
 /**
  * Add CSS
  *
  * @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_callback($handler_id, array $args, array &$data)
 {
     $this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/legacy.css");
     //need js for chooser-widgets for list of hour - because of dynamic load loading is needed here
     midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/chooser/jquery.chooser_widget.js");
     $this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/chooser/jquery.chooser_widget.css");
     if ($handler_id == 'task_view') {
         org_openpsa_widgets_contact::add_head_elements();
         $data['calendar_node'] = midcom_helper_misc::find_node_by_component('org.openpsa.calendar');
     }
 }
Esempio n. 24
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_article = new midcom_db_article();
     $this->_article->topic = $this->_content_topic->id;
     if (array_key_exists('name', $this->_defaults) && $this->_defaults['name'] == 'index') {
         // Store this to article directly in case name field is not editable in schema
         $this->_article->name = 'index';
     }
     if (!$this->_article->create()) {
         debug_print_r('We operated on this object:', $this->_article);
         throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     // Callback possibility
     if ($this->_config->get('callback_function')) {
         if ($this->_config->get('callback_snippet')) {
             midcom_helper_misc::include_snippet_php($this->_config->get('callback_snippet'));
         }
         $callback = $this->_config->get('callback_function');
         $callback($this->_article, $this->_content_topic);
     }
     return $this->_article;
 }
Esempio n. 25
0
 /**
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_generator($handler_id, array &$data)
 {
     midcom_show_style('sales_report-deliverable-start');
     // Quick workaround to Bergies lazy determination of whether this is user's or everyone's report...
     if ($this->_request_data['query_data']['resource'] == 'user:'******'auth')->user->guid) {
         // My report
         $data['handler_id'] = 'deliverable_report';
     } else {
         // Generic report
         $data['handler_id'] = 'sales_report';
     }
     /*** Copied from sales/handler/deliverable/report.php ***/
     midcom_show_style('sales_report-deliverable-header');
     $invoices_node = midcom_helper_misc::find_node_by_component('org.openpsa.invoices');
     $sums_per_person = array();
     $sums_all = array('price' => 0, 'cost' => 0, 'profit' => 0);
     $odd = true;
     foreach ($data['invoices'] as $deliverable_guid => $invoices) {
         if (count($invoices) == 0) {
             // No invoices sent in this project, skip
             continue;
         }
         try {
             $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($deliverable_guid);
             $product = org_openpsa_products_product_dba::get_cached($deliverable->product);
             $salesproject = org_openpsa_sales_salesproject_dba::get_cached($deliverable->salesproject);
             $customer = midcom_db_group::get_cached($salesproject->customer);
         } catch (midcom_error $e) {
             continue;
         }
         if (!array_key_exists($salesproject->owner, $sums_per_person)) {
             $sums_per_person[$salesproject->owner] = array('price' => 0, 'cost' => 0, 'profit' => 0);
         }
         // Calculate the price and cost from invoices
         $invoice_price = 0;
         $data['invoice_string'] = '';
         $invoice_cycle_numbers = array();
         foreach ($invoices as $invoice) {
             $invoice_price += $invoice->sum;
             $invoice_class = $invoice->get_status();
             if ($invoices_node) {
                 $invoice_label = "<a class=\"{$invoice_class}\" href=\"{$invoices_node[MIDCOM_NAV_FULLURL]}invoice/{$invoice->guid}/\">" . $invoice->get_label() . "</a>";
             } else {
                 $invoice_label = $invoice->get_label();
             }
             if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
                 $invoice_cycle_numbers[] = (int) $invoice->parameter('org.openpsa.sales', 'cycle_number');
             }
             $data['invoice_string'] .= "<li class=\"{$invoice_class}\">{$invoice_label}</li>\n";
         }
         if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
             // This is a subscription, it should be shown only if it is the first invoice
             if (!in_array(1, $invoice_cycle_numbers)) {
                 continue;
                 // This will skip to next deliverable
             }
             $scheduler = new org_openpsa_invoices_scheduler($deliverable);
             if ($deliverable->end == 0) {
                 // Subscription doesn't have an end date, use specified amount of months for calculation
                 $cycles = $scheduler->calculate_cycles($this->_config->get('subscription_profit_months'));
                 $data['calculation_basis'] = sprintf($data['l10n']->get('%s cycles in %s months'), $cycles, $this->_config->get('subscription_profit_months'));
             } else {
                 $cycles = $scheduler->calculate_cycles();
                 $data['calculation_basis'] = sprintf($data['l10n']->get('%s cycles, %s - %s'), $cycles, strftime('%x', $deliverable->start), strftime('%x', $deliverable->end));
             }
             $price = $deliverable->price * $cycles;
             $cost = $deliverable->cost * $cycles;
         } else {
             // This is a single delivery, calculate cost as percentage as it may be invoiced in pieces
             if ($deliverable->price) {
                 $cost_percentage = 100 / $deliverable->price * $invoice_price;
                 $cost = $deliverable->cost / 100 * $cost_percentage;
             } else {
                 $cost_percentage = 100;
                 $cost = $deliverable->cost;
             }
             $price = $invoice_price;
             $data['calculation_basis'] = sprintf($data['l10n']->get('%s%% of %s'), round($cost_percentage), $deliverable->price);
         }
         // And now just count the profit
         $profit = $price - $cost;
         $data['customer'] = $customer;
         $data['salesproject'] = $salesproject;
         $data['deliverable'] = $deliverable;
         $data['price'] = $price;
         $sums_per_person[$salesproject->owner]['price'] += $price;
         $sums_all['price'] += $price;
         $data['cost'] = $cost;
         $sums_per_person[$salesproject->owner]['cost'] += $cost;
         $sums_all['cost'] += $cost;
         $data['profit'] = $profit;
         $sums_per_person[$salesproject->owner]['profit'] += $profit;
         $sums_all['profit'] += $profit;
         if ($odd) {
             $data['row_class'] = '';
             $odd = false;
         } else {
             $data['row_class'] = ' class="even"';
             $odd = true;
         }
         midcom_show_style('sales_report-deliverable-item');
     }
     $data['sums_per_person'] = $sums_per_person;
     $data['sums_all'] = $sums_all;
     midcom_show_style('sales_report-deliverable-footer');
     /*** /Copied from sales/handler/deliverable/report.php ***/
     midcom_show_style('sales_report-deliverable-end');
 }
Esempio n. 26
0
 /**
  * Loads the file/snippet necessary for a given plugin, according to its configuration.
  *
  * @param string $namespace The plugin namespace to use.
  * @param string $plugin The plugin to load from the namespace.
  */
 public function _load_plugin_class($namespace, $plugin)
 {
     $plugin_config = self::$_plugin_namespace_config[$namespace][$plugin];
     // Sanity check, we return directly if the configured class name is already
     // available (dynamic_load could trigger this).
     if (class_exists($plugin_config['class'])) {
         return;
     }
     $i = strpos($plugin_config['src'], ':');
     if ($i == false) {
         $method = 'snippet';
         $src = $plugin_config['src'];
     } else {
         $method = substr($plugin_config['src'], 0, $i);
         $src = substr($plugin_config['src'], $i + 1);
     }
     switch ($method) {
         case 'file':
             require_once MIDCOM_ROOT . $src;
             break;
         case 'component':
             midcom::get('componentloader')->load($src);
             break;
         case 'snippet':
             midcom_helper_misc::include_snippet_php($src);
             break;
         default:
             throw new midcom_error("The plugin loader method {$method} is unknown, cannot continue.");
     }
     if (!class_exists($plugin_config['class'])) {
         throw new midcom_error("Failed to load the plugin {$namespace}/{$plugin}, implementation class not available.");
     }
 }
Esempio n. 27
0
 private function _create_topic($prefix)
 {
     if (!empty($this->_new_topic->symlink)) {
         $name = $this->_new_topic->name;
         $topic = $this->_new_topic;
         while (!empty($topic->symlink)) {
             // Only direct symlinks are supported, but indirect symlinks are ok as we change them to direct ones here
             $this->_new_topic->symlink = $topic->symlink;
             try {
                 $topic = new midcom_db_topic($topic->symlink);
             } catch (midcom_error $e) {
                 debug_add("Could not get target for symlinked topic #{$this->_new_topic->id}: " . $e->getMessage(), MIDCOM_LOG_ERROR);
                 $topic = $this->_new_topic;
                 $this->_new_topic->purge();
                 throw new midcom_error("Refusing to create this symlink because its target folder was not found: " . $e->getMessage());
             }
             $name = $topic->name;
         }
         if ($this->_new_topic->up == $topic->up) {
             $this->_new_topic->purge();
             throw new midcom_error("Refusing to create this symlink because it is located in the same " . "folder as its target. You must have made a mistake. Sorry, but this " . "was for your own good.");
         }
         if ($this->_new_topic->up == $topic->id) {
             $this->_new_topic->purge();
             throw new midcom_error("Refusing to create this symlink because its parent folder is the same " . "folder as its target. You must have made a mistake because this would " . "have created an infinite loop situation. The whole site would have " . "been completely and irrevocably broken if this symlink would have been " . "allowed to exist. Infinite loops can not be allowed. Sorry, but this " . "was for your own good.");
         }
         $this->_new_topic->update();
         if (!midcom_admin_folder_management::is_child_listing_finite($topic)) {
             $this->_new_topic->purge();
             throw new midcom_error("Refusing to create this symlink because it would have created an " . "infinite loop situation. The whole site would have been completely " . "and irrevocably broken if this symlink would have been allowed to " . "exist. Please redesign your usage of symlinks. Infinite loops can " . "not be allowed. Sorry, but this was for your own good.");
         }
         $this->_new_topic->name = $name;
         while (!$this->_new_topic->update() && midcom_connection::get_error() == MGD_ERR_DUPLICATE) {
             $this->_new_topic->name .= "-link";
         }
     }
     midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder created'));
     // Generate name if it is missing
     if (!$this->_new_topic->name) {
         $this->_new_topic->name = midcom_helper_misc::generate_urlname_from_string($this->_new_topic->extra);
         $this->_new_topic->update();
     }
     // Get the relocation url
     $url = "{$prefix}{$this->_new_topic->name}/";
     return $url;
 }
Esempio n. 28
0
 /**
  * Synchronizes the attachments info array with the attachment referenced by the
  * identifier.
  *
  * @param mixed $identifier The identifier of the attachment to update
  */
 protected function _update_attachment_info($identifier)
 {
     // Shortcuts
     $att = $this->attachments[$identifier];
     $stats = $att->stat();
     $info = array();
     $info['filename'] = $att->name;
     $info['description'] = $att->title;
     $info['mimetype'] = $att->mimetype;
     $info['url'] = midcom_db_attachment::get_url($att);
     $info['id'] = $att->id;
     $info['guid'] = $att->guid;
     $info['filesize'] = $stats[7];
     $info['formattedsize'] = midcom_helper_misc::filesize_to_string($stats[7]);
     $info['lastmod'] = $stats[9];
     $info['isoformattedlastmod'] = strftime('%Y-%m-%d %T', $stats[9]);
     $this->_update_attachment_info_additional($info, $att);
     $info['object'] = $this->attachments[$identifier];
     $info['identifier'] = $identifier;
     $this->attachments_info[$identifier] = $info;
 }
Esempio n. 29
0
 /**
  * This is the actual code which filters and saves a derived image.
  *
  * @param string $identifier The derived image to construct.
  * @return boolean Indicating success
  */
 function _save_derived_image($identifier)
 {
     $this->_current_tmpname = $this->_filter->create_tmp_copy($this->_original_tmpname);
     if (!$this->_filter->set_file($this->_current_tmpname) || !$this->_filter->process_chain($this->derived_images[$identifier])) {
         return false;
     }
     if (isset($this->_identifier)) {
         // we come from the image*s* type
         $blob_identifier = "{$this->_identifier}{$identifier}";
         $title = $this->_title;
     } else {
         $blob_identifier = $identifier;
         $title = $this->title;
     }
     if (array_key_exists($identifier, $this->_pending_attachments)) {
         unset($this->_pending_attachments[$identifier]);
         return $this->update_attachment($blob_identifier, "{$identifier}_{$this->_filename}", $title, midcom_helper_misc::get_mimetype($this->_current_tmpname), $this->_current_tmpname, false);
     }
     if (isset($this->_attachment_map)) {
         $this->_attachment_map[$blob_identifier] = array($this->_identifier, $identifier);
     }
     return $this->add_attachment($blob_identifier, "{$identifier}_{$this->_filename}", $title, midcom_helper_misc::get_mimetype($this->_current_tmpname), $this->_current_tmpname, false);
 }
Esempio n. 30
0
 function convert_to_html()
 {
     $this->value = (string) $this->value;
     switch ($this->output_mode) {
         case 'code':
             return '<pre style="overflow:auto">' . htmlspecialchars($this->value, $this->specialchars_quotes, $this->specialchars_charset) . '</pre>';
         case 'pre':
             return '<pre style="white-space: pre-wrap">' . htmlspecialchars($this->value, $this->specialchars_quotes, $this->specialchars_charset) . '</pre>';
         case 'specialchars':
             return htmlspecialchars($this->value, $this->specialchars_quotes, $this->specialchars_charset);
         case 'nl2br':
             return nl2br(htmlentities($this->value, $this->specialchars_quotes, $this->specialchars_charset));
         case 'midgard_f':
             return midcom_helper_misc::format_variable($this->value, 'f');
         case 'midgard_F':
             return midcom_helper_misc::format_variable($this->value, 'F');
         case 'markdown':
             static $markdown = null;
             if (!$markdown) {
                 midcom::get('componentloader')->load_library('net.nehmer.markdown');
                 $markdown = new net_nehmer_markdown_markdown();
             }
             if (!$this->purify || !$this->purify_markdown_on_output) {
                 // Return the Markdown straight away
                 return $markdown->render($this->value);
             }
             // Run the Markdown-generated HTML through Purifier to ensure consistency. This is expensive, however
             return $this->purify_string($markdown->render($this->value));
         case substr($this->output_mode, 0, 1) == 'x':
             // Run the contents through a custom formatter registered via mgd_register_filter
             return midcom_helper_misc::format_variable($this->value, $this->output_mode);
         default:
         case 'html':
             return $this->value;
     }
 }