Пример #1
1
 public static function prepare_dir($prefix)
 {
     $config = midcom_baseclasses_components_configuration::get('midcom.helper.filesync', 'config');
     $path = $config->get('filesync_path');
     if (!file_exists($path)) {
         $parent = dirname($path);
         if (!is_writable($parent)) {
             throw new midcom_error("Directory {$parent} is not writable");
         }
         if (!mkdir($path)) {
             throw new midcom_error("Failed to create directory {$path}. Reason: " . $php_errormsg);
         }
     }
     if (substr($path, -1) != '/') {
         $path .= '/';
     }
     $module_dir = "{$path}{$prefix}";
     if (!file_exists($module_dir)) {
         if (!is_writable($path)) {
             throw new midcom_error("Directory {$path} is not writable");
         }
         if (!mkdir($module_dir)) {
             throw new midcom_error("Failed to create directory {$module_dir}. Reason: " . $php_errormsg);
         }
     }
     return "{$module_dir}/";
 }
Пример #2
0
 /**
  * Indexes a product
  *
  * This function is usually called statically from various handlers.
  *
  * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event.
  * @param midcom_services_indexer &$indexer The indexer instance to use.
  * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code
  *     tries to load a new topic instance from the database identified by this parameter.
  */
 public static function index(&$dm, &$indexer, $topic, $config = null)
 {
     if ($config == null) {
         $config = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config');
     }
     $object =& $dm->storage->object;
     if (!is_object($topic)) {
         $topic = new midcom_db_topic($topic);
     }
     // Don't index directly, that would lose a reference due to limitations
     // of the index() method. Needs fixes there.
     $document = $indexer->new_document($dm);
     if (midcom::get('dbfactory')->is_a($object, 'org_openpsa_products_product_dba')) {
         if ($config->get('enable_scheduling')) {
             // Check start/end for products
             if ($object->start != 0 && $object->start > time() || $object->end != 0 && $object->end < time()) {
                 // Not in market, remove from index
                 $indexer->delete($document->RI);
                 return;
             }
             // FIXME: add midcom at job or somesuch to reindex products after their end time (and start time if in the future)
         }
     }
     $document->topic_guid = $topic->guid;
     $document->component = $topic->component;
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     $document->topic_url = $node[MIDCOM_NAV_FULLURL];
     $document->read_metadata_from_object($object);
     $document->content = "{$dm->schema->name} {$dm->schema->description} {$document->content}";
     $indexer->index($document);
 }
Пример #3
0
 /**
  * function that loads the necessary javascript & css files for jqgrid
  */
 public static function add_head_elements()
 {
     if (self::$_head_elements_added) {
         return;
     }
     $version = midcom_baseclasses_components_configuration::get('org.openpsa.widgets', 'config')->get('jqgrid_version');
     $jqgrid_path = '/org.openpsa.widgets/jquery.jqGrid-' . $version . '/';
     $head = midcom::get('head');
     //first enable jquery - just in case it isn't loaded
     $head->enable_jquery();
     $head->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.core.min.js');
     //needed js/css-files for jqgrid
     $lang = "en";
     $language = midcom::get('i18n')->get_current_language();
     if (file_exists(MIDCOM_STATIC_ROOT . $jqgrid_path . 'js/i18n/grid.locale-' . $language . '.js')) {
         $lang = $language;
     }
     $head->add_jsfile(MIDCOM_STATIC_URL . $jqgrid_path . 'js/i18n/grid.locale-' . $lang . '.js');
     $head->add_jsfile(MIDCOM_STATIC_URL . $jqgrid_path . 'js/jquery.jqGrid.min.js');
     org_openpsa_widgets_ui::add_head_elements();
     $head->add_jsfile(MIDCOM_STATIC_URL . '/org.openpsa.widgets/jqGrid.custom.js');
     $head->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.widget.min.js');
     $head->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.mouse.min.js');
     $head->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.resizable.min.js');
     $head->add_stylesheet(MIDCOM_STATIC_URL . $jqgrid_path . 'css/ui.jqgrid.css');
     $head->add_stylesheet(MIDCOM_STATIC_URL . '/org.openpsa.widgets/jqGrid.custom.css');
     $head->add_jquery_ui_theme();
     self::$_head_elements_added = true;
 }
Пример #4
0
 /**
  */
 public function process_deliverable(org_openpsa_sales_salesproject_deliverable_dba $deliverable, $cycle_number = null)
 {
     $this->_deliverable = $deliverable;
     // Recalculate price to catch possible unit changes
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator');
     $client = new $client_class();
     $client->run($this->_deliverable);
     $this_cycle_amount = $client->get_price();
     if ($this_cycle_amount == 0) {
         debug_add('Invoice sum 0, skipping invoice creation');
         return 0;
     }
     $this->_invoice = $this->_probe_invoice($cycle_number);
     if (!$this->_invoice->update()) {
         throw new midcom_error("The invoice could not be saved. Last Midgard error was: " . midcom_connection::get_error_string());
     }
     // TODO: Create invoicing task if assignee is defined
     $items = $client->get_invoice_items($this->_invoice);
     foreach ($items as $item) {
         $item->deliverable = $this->_deliverable->id;
         $item->skip_invoice_update = true;
         if ($item->id) {
             $stat = $item->update();
         } else {
             $stat = $item->create();
         }
         if (!$stat) {
             throw new midcom_error('Failed to save item to disk, ' . midcom_connection::get_error_string());
         }
     }
     org_openpsa_invoices_invoice_item_dba::update_invoice($this->_invoice);
     org_openpsa_invoices_invoice_item_dba::update_deliverable($this->_deliverable);
     return $this_cycle_amount;
 }
Пример #5
0
 /**
  * @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_view($handler_id, array $args, array &$data)
 {
     $data['name'] = $args[0];
     if (!midcom::get('componentloader')->is_installed($data['name'])) {
         throw new midcom_error_notfound("Component {$data['name']} is not installed.");
     }
     $componentpath = midcom::get('componentloader')->path_to_snippetpath($data['name']);
     // Load and parse the global config
     $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc");
     if (!$cfg) {
         // hmmm... that should never happen
         $cfg = array();
     }
     $config = new midcom_helper_configuration($cfg);
     // Go for the sitewide default
     $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$data['name']}/config.inc");
     if ($cfg !== false) {
         $config->store($cfg, false);
     }
     // Finally, check the sitegroup config
     $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$data['name']}/config");
     if ($cfg !== false) {
         $config->store($cfg, false);
     }
     $data['config'] =& $config;
     $this->_update_breadcrumb($data['name']);
     $this->_prepare_toolbar($data);
     midcom::get('head')->set_pagetitle($data['view_title']);
 }
Пример #6
0
 private static function _load_backend($backend, array $params)
 {
     $default_params = midcom_baseclasses_components_configuration::get('org.openpsa.mail', 'config')->get($backend . '_params');
     if (is_array($default_params)) {
         $params = array_merge($default_params, $params);
     }
     $classname = 'org_openpsa_mail_backend_' . $backend;
     return new $classname($params);
 }
Пример #7
0
 /**
  * Initializes the class with a given feed
  */
 public function __construct($feed)
 {
     $this->_feed = $feed;
     $this->_node = new midcom_db_topic($this->_feed->node);
     $this->_component = 'net.nemein.rss';
     if ($this->_node->component) {
         $this->_node_config = midcom_baseclasses_components_configuration::get($this->_node->component, 'config');
     }
     parent::__construct();
 }
Пример #8
0
 public function __construct($id = null)
 {
     parent::__construct($id);
     /* To specify different values for MMS and SMS first unset the MMS
        values to destroy the reference, then set correct value */
     $this->mms_lib =& $this->sms_lib;
     $this->mms_lib_api =& $this->sms_lib_api;
     $this->mms_lib_location =& $this->sms_lib_location;
     $this->mms_lib_client_id =& $this->sms_lib_client_id;
     $this->mms_lib_user =& $this->sms_lib_user;
     $this->mms_lib_password =& $this->sms_lib_password;
     $config = midcom_baseclasses_components_configuration::get('org.openpsa.directmarketing', 'config');
     $this->chunk_size = $config->get('chunk_size');
 }
Пример #9
0
 public function test_calculate_day()
 {
     $topic = $this->get_component_node('org.openpsa.mypage');
     $config = midcom_baseclasses_components_configuration::get('org.openpsa.mypage', 'config');
     $viewer = new org_openpsa_mypage_viewer($topic, $config);
     $viewer->calculate_day('2011-10-26');
     $this->assertEquals('2011-10-26', $viewer->_request_data['this_day']);
     $this->assertEquals(mktime(0, 0, 0, 10, 26, 2011), $viewer->_request_data['day_start']);
     $this->assertEquals(mktime(23, 59, 59, 10, 26, 2011), $viewer->_request_data['day_end']);
     $this->assertEquals('2011-10-25', $viewer->_request_data['prev_day']);
     $this->assertEquals('2011-10-27', $viewer->_request_data['next_day']);
     $this->assertEquals(mktime(0, 0, 0, 10, 24, 2011), $viewer->_request_data['week_start']);
     $this->assertEquals(mktime(23, 59, 59, 10, 30, 2011), $viewer->_request_data['week_end']);
 }
Пример #10
0
 public function load_schemadb()
 {
     // Load SchemaDb
     $schemadb_config_path = midcom::get('componentloader')->path_to_snippetpath($this->_request_data['name']) . '/config/config_schemadb.inc';
     $schemadb = null;
     $schema = 'default';
     if (file_exists($schemadb_config_path)) {
         // Check that the schema is valid DM2 schema
         $schema_array = midcom_baseclasses_components_configuration::read_array_from_file($schemadb_config_path);
         if (isset($schema_array['config'])) {
             $schema = 'config';
         }
         if (!isset($schema_array[$schema]['name'])) {
             // This looks like DM2 schema
             $schemadb = midcom_helper_datamanager2_schema::load_database("file:/{$schemadb_config_path}");
         }
         // TODO: Log error on deprecated config schema?
     }
     if (!$schemadb) {
         // Create dummy schema. Naughty component would not provide config schema.
         $schemadb = midcom_helper_datamanager2_schema::load_database("file:/midgard/admin/asgard/config/schemadb_libconfig.inc");
     }
     $schemadb[$schema]->l10n_schema = $this->_request_data['name'];
     foreach ($this->_request_data['config']->_global as $key => $value) {
         // try to sniff what fields are missing in schema
         if (!array_key_exists($key, $schemadb[$schema]->fields)) {
             $schemadb[$schema]->append_field($key, $this->_detect_schema($key, $value));
             $schemadb[$schema]->fields[$key]['title'] = midcom::get('i18n')->get_string($schemadb[$schema]->fields[$key]['title'], $schemadb[$schema]->l10n_schema);
         }
         if (!isset($this->_request_data['config']->_local[$key]) || $this->_request_data['config']->_local[$key] == $this->_request_data['config']->_global[$key]) {
             // No local configuration setting, note to user that this is the global value
             $schemadb[$schema]->fields[$key]['title'] = midcom::get('i18n')->get_string($schemadb[$schema]->fields[$key]['title'], $schemadb[$schema]->l10n_schema);
             $schemadb[$schema]->fields[$key]['title'] .= " <span class=\"global\">(" . midcom::get('i18n')->get_string('global value', 'midgard.admin.asgard') . ")</span>";
         }
     }
     // Prepare defaults
     foreach ($this->_request_data['config']->get_all() as $key => $value) {
         if (!isset($schemadb[$schema]->fields[$key])) {
             // Skip
             continue;
         }
         if (is_array($value)) {
             $schemadb[$schema]->fields[$key]['default'] = "array(\n" . $this->_draw_array($value, '    ') . ")";
         } else {
             $schemadb[$schema]->fields[$key]['default'] = $value;
         }
     }
     return $schemadb;
 }
Пример #11
0
 public function mail($recipients, array $headers, $body)
 {
     $hdr = '';
     $subject = '';
     reset($headers);
     foreach ($headers as $key => $value) {
         if (strtolower($key) == 'to') {
             continue;
         } else {
             if (strtolower($key) == 'subject') {
                 $subject = $value;
                 continue;
             }
         }
         $hdr .= "{$key}: {$value}\n";
     }
     $additional_parameters = midcom_baseclasses_components_configuration::get('org.openpsa.mail', 'config')->get('mail_additional_params');
     return mail($recipients, $subject, $body, $hdr, $additional_parameters);
 }
Пример #12
0
 public function get_libraries()
 {
     $libs = array();
     foreach (midcom::get('componentloader')->manifests as $name => $manifest) {
         if (!array_key_exists('package.xml', $manifest->_raw_data)) {
             // This component is not yet packaged, skip
             continue;
         }
         if ($manifest->purecode) {
             midcom::get('componentloader')->load_graceful($name);
             $configpath = midcom::get('componentloader')->path_to_snippetpath($name) . "/config/config.inc";
             $lib = midcom_baseclasses_components_configuration::read_array_from_file("{$configpath}");
             if (!$lib) {
                 continue;
             }
             $libs[$name] = $manifest;
         }
     }
     return $libs;
 }
Пример #13
0
 /**
  * Locates the root event
  */
 public static function find_root_event()
 {
     if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
         midcom::get('componentloader')->load_graceful('org.openpsa.calendar');
         //Doublecheck
         if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
             return false;
         }
     }
     $data = midcom_baseclasses_components_configuration::get('org.openpsa.calendar');
     //Check if we have already initialized
     if (isset($data['calendar_root_event']) && is_object($data['calendar_root_event'])) {
         return $data['calendar_root_event'];
     }
     $root_event = false;
     $root_guid = $data['config']->get('calendar_root_event');
     if (mgd_is_guid($root_guid)) {
         $root_event = org_openpsa_calendar_event_dba::get_cached($root_guid);
     } else {
         // Check for calendar event tree.
         $qb = org_openpsa_calendar_event_dba::new_query_builder();
         $qb->add_constraint('title', '=', '__org_openpsa_calendar');
         $qb->add_constraint('up', '=', '0');
         $ret = $qb->execute();
         if (is_array($ret) && count($ret) > 0) {
             $root_event = $ret[0];
             $siteconfig = org_openpsa_core_siteconfig::get_instance();
             $topic_guid = $siteconfig->get_node_guid('org.openpsa.calendar');
             if ($topic_guid) {
                 $topic = new midcom_db_topic($topic_guid);
                 $topic->set_parameter('org.openpsa.calendar', 'calendar_root_event', $root_event->guid);
             }
         } else {
             debug_add("OpenPSA Calendar root event could not be found", MIDCOM_LOG_ERROR);
             //Attempt to auto-initialize
             $root_event = self::create_root_event();
         }
     }
     $data['calendar_root_event'] = $root_event;
     return $root_event;
 }
Пример #14
0
<?php

// Check the user preference and configuration
$config = midcom_baseclasses_components_configuration::get('midgard.admin.asgard', 'config');
if (midgard_admin_asgard_plugin::get_preference('escape_frameset') || midgard_admin_asgard_plugin::get_preference('escape_frameset') !== '0' && $config->get('escape_frameset')) {
    midcom::get('head')->add_jsonload('if(top.frames.length != 0 && top.location.href != this.location.href){top.location.href = this.location.href}');
}
//don't send an XML prolog for IE, it knocks IE6 into quirks mode
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== false) {
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
}
$pref_found = false;
if ($width = midgard_admin_asgard_plugin::get_preference('offset')) {
    $navigation_width = $width - 40;
    $content_offset = $width + 2;
    $pref_found = true;
}
// JavasScript libraries required by Asgard
midcom::get('head')->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.core.min.js');
midcom::get('head')->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.widget.min.js');
midcom::get('head')->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.mouse.min.js');
midcom::get('head')->add_jsfile(MIDCOM_JQUERY_UI_URL . '/ui/jquery.ui.draggable.min.js');
midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/resize.js');
midcom::get('head')->add_jscript("var MIDGARD_ROOT = '" . midcom_connection::get_url('self') . "';");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php 
echo midcom::get('i18n')->get_current_language();
?>
" lang="<?php 
Пример #15
0
 public function get_plugin_handlers()
 {
     $handlers = midcom_baseclasses_components_configuration::get($this->_component, 'routes');
     return $handlers;
 }
Пример #16
0
 public function set_active_leaf($leaf_id)
 {
     midcom_baseclasses_components_configuration::set($this->_component, 'active_leaf', $leaf_id);
 }
Пример #17
0
 /**
  * @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_edit($handler_id, array $args, array &$data)
 {
     $this->_component_name = $args[0];
     if (!midcom::get('componentloader')->is_installed($this->_component_name)) {
         throw new midcom_error_notfound("Component {$this->_component_name} is not installed.");
     }
     $componentpath = midcom::get('componentloader')->path_to_snippetpath($this->_component_name);
     // Load and parse the global config
     $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc");
     if (!$cfg) {
         // hmmm... that should never happen
         $cfg = array();
     }
     $this->_libconfig = new midcom_helper_configuration($cfg);
     // Go for the sitewide default
     $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$this->_component_name}}/config.inc");
     if ($cfg !== false) {
         $this->_libconfig->store($cfg, false);
     }
     // Finally, check the sitegroup config
     $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$this->_component_name}/config");
     if ($cfg !== false) {
         $this->_libconfig->store($cfg, false);
     }
     $this->_controller = $this->get_controller('nullstorage');
     switch ($this->_controller->process_form()) {
         case 'save':
             if ($this->_save_configuration()) {
                 mgd_cache_invalidate();
                 midcom::get('uimessages')->add($this->_l10n->get('host configuration'), $this->_l10n->get('settings saved successfully') . $this->_codeinit->id, 'ok');
             } else {
                 midcom::get('uimessages')->add($this->_l10n->get('host configuration'), sprintf($this->_l10n->get('failed to save settings, reason %s')), 'error');
             }
             // *** FALL-THROUGH ***
         // *** FALL-THROUGH ***
         case 'cancel':
             return new midcom_response_relocate('__mfa/asgard_midcom.admin.libconfig/edit/' . $this->_component_name);
     }
     $data['controller'] =& $this->_controller;
     $this->_update_breadcrumb();
     midcom::get('head')->set_pagetitle($data['view_title']);
 }
Пример #18
0
 /**
  * Returns the currently selected leaf of the request.
  *
  * @return int The active leaf ID out of the component data storage.
  */
 public function get_current_leaf()
 {
     return midcom_baseclasses_components_configuration::get($this->_component, 'active_leaf');
 }
Пример #19
0
 /**
  * function checks if hour_report is invoiceable & applies minimum time slot
  */
 function modify_hours_by_time_slot($update = true)
 {
     if ($this->invoiceable) {
         $task = new org_openpsa_projects_task_dba($this->task);
         $time_slot = (double) $task->get_parameter('org.openpsa.projects.projectbroker', 'minimum_slot');
         if (empty($time_slot) || $time_slot == 0) {
             $time_slot = (double) midcom_baseclasses_components_configuration::get('org.openpsa.projects', 'config')->get('default_minimum_time_slot');
             if (empty($time_slot) || $time_slot == 0) {
                 $time_slot = 1;
             }
         }
         $time_slot_amount = $this->hours / $time_slot;
         $time_slot_amount_int = intval($time_slot_amount);
         $difference = $time_slot_amount - (double) $time_slot_amount_int;
         if ($difference > 0.5 || $time_slot_amount_int == 0) {
             $time_slot_amount_int++;
         }
         $this->hours = $time_slot_amount_int * $time_slot;
         if ($update) {
             $this->update();
         }
     }
 }
Пример #20
0
    <form method="post">
        <label>
            URL/path
            <input type="text" name="address" value="/tmp/__PRODUCT_CODE__.jpg" />
        </label>
        <input type="submit" value="Import images" />
    </form>
    <?php 
} else {
    midcom::get()->disable_limits();
    // Import product images
    $qb = org_openpsa_products_product_dba::new_query_builder();
    $qb->add_constraint('code', '<>', '');
    $products = $qb->execute();
    $schemadb = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('schemadb_product');
    $schema = midcom_helper_datamanager2_schema::load_database($schema);
    $datamanager = new midcom_helper_datamanager2_datamanager($schema);
    foreach ($products as $product) {
        // Get old image
        $image = file_get_contents(str_replace('__PRODUCT_CODE__', $product->code, $_POST['address']));
        if (empty($image)) {
            continue;
        }
        // Save image to a temp file
        $tmp_name = tempnam($GLOBALS['midcom_config']['midcom_tempdir'], 'org_openpsa_products_product_oldimage_');
        $fp = fopen($tmp_name, 'w');
        if (!fwrite($fp, $image)) {
            //Could not write, clean up and continue
            echo "Error when writing file {$tmp_name}";
            fclose($fp);
Пример #21
0
 /**
  * Statically callable method to map extended classes
  *
  * For example org.openpsa.* components often expand core objects,
  * in config we specify which classes we wish to substitute with which
  *
  * @param string $schema_type classname to check rewriting for
  * @return string new classname (or original in case no rewriting is to be done)
  */
 public static function class_rewrite($schema_type)
 {
     static $extends = false;
     if ($extends === false) {
         $extends = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('class_extends');
         // Safety against misconfiguration
         if (!is_array($extends)) {
             debug_add("config->get('class_extends') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR);
             return $schema_type;
         }
     }
     if (isset($extends[$schema_type]) && class_exists($extends[$schema_type])) {
         return $extends[$schema_type];
     }
     return $schema_type;
 }
Пример #22
0
 /**
  * Helper function that sets the default object mode
  */
 public static function get_default_mode(&$data)
 {
     //only set mode once per request
     if (!empty($data['default_mode'])) {
         return $data['default_mode'];
     }
     if (midcom_baseclasses_components_configuration::get('midgard.admin.asgard', 'config')->get('edit_mode') == 1) {
         $data['default_mode'] = 'edit';
     } else {
         $data['default_mode'] = 'view';
     }
     if (midgard_admin_asgard_plugin::get_preference('edit_mode') == 1) {
         $data['default_mode'] = 'edit';
     } else {
         $data['default_mode'] = 'view';
     }
     return $data['default_mode'];
 }
Пример #23
0
 function _load_defaults()
 {
     $this->_defaults['date'] = time();
     $this->_defaults['deliverydate'] = time();
     // Set default due date and copy customer remarks to invoice description
     if (array_key_exists('customer', $this->_request_data)) {
         $dummy = new org_openpsa_invoices_invoice_dba();
         $dummy->customer = $this->_request_data['customer']->id;
         $this->_defaults['vat'] = $dummy->get_default('vat');
         if (is_a($this->_request_data['customer'], 'org_openpsa_contacts_person_dba')) {
             $this->_defaults['customerContact'] = $this->_request_data['customer']->id;
         }
         // we got a customer, set description default
         $this->_defaults['description'] = $dummy->get_default('remarks');
         unset($dummy);
     } else {
         $due_date = $this->_config->get('default_due_days') * 3600 * 24 + time();
         $this->_defaults['due'] = $due_date;
     }
     // Generate invoice number
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator');
     $calculator = new $client_class();
     $this->_defaults['number'] = $calculator->generate_invoice_number();
     $this->_defaults['owner'] = midcom_connection::get_user();
 }
Пример #24
0
 public static function get_config_value($value)
 {
     $config = midcom_baseclasses_components_configuration::get('org.openpsa.widgets', 'config');
     return $config->get($value);
 }
Пример #25
0
<?php

midcom::get('auth')->require_valid_user();
$user = midcom::get('auth')->user->get_storage();
// Use the FireEagle PHP library from http://fireeagle.yahoo.net/developer/code/php
require_once MIDCOM_ROOT . '/external/fireeagle.php';
$access_key = $user->get_parameter('net.yahoo.fireeagle', 'access_key');
$access_secret = $user->get_parameter('net.yahoo.fireeagle', 'access_secret');
$fireeagle_consumer_key = midcom_baseclasses_components_configuration::get('org.routamc.positioning', 'config')->get('fireeagle_consumer_key');
$fireeagle_consumer_secret = midcom_baseclasses_components_configuration::get('org.routamc.positioning', 'config')->get('fireeagle_consumer_secret');
if (!$access_key || !$access_secret) {
    $session = new midcom_services_session('org_routamc_positioning_fireeagle');
    if (isset($_GET['f']) && $_GET['f'] == 'start') {
        // get a request token + secret from FE and redirect to the authorization page
        $fireeagle = new FireEagle($fireeagle_consumer_key, $fireeagle_consumer_secret);
        $request_token = $fireeagle->getRequestToken();
        if (!isset($request_token['oauth_token']) || !is_string($request_token['oauth_token']) || !isset($request_token['oauth_token_secret']) || !is_string($request_token['oauth_token_secret'])) {
            throw new midcom_error("Failed to get FireEagle request token\n");
        }
        // Save request token to session and redirect user
        $session->set('auth_state', 'start');
        $session->set('request_token', $request_token['oauth_token']);
        $session->set('request_secret', $request_token['oauth_token_secret']);
        ?>
        <p><a href="<?php 
        echo $fireeagle->getAuthorizeURL($request_token['oauth_token']);
        ?>
" target="_blank">Authorize this application</a></p>
        <p><a href="?f=callback">And then click here</a></p>
        <?php 
        midcom::get()->finish();
Пример #26
0
 /**
  * Initializes the request handler class, called by the component interface after
  * instantiation. Required to allow safe $this references during startup.
  *
  * @param string $component The name of the component.
  */
 public function initialize($component)
 {
     $this->_component = $component;
     midcom_core_context::get()->set_custom_key('request_data', $this->_request_data);
     $this->_request_data['config'] =& $this->_config;
     $this->_request_data['topic'] = null;
     $this->_request_data['l10n'] = $this->_l10n;
     $this->_request_data['l10n_midcom'] = $this->_l10n_midcom;
     if (empty(self::$_plugin_namespace_config)) {
         $this->_register_core_plugin_namespaces();
     }
     $manifest = midcom::get('componentloader')->manifests[$this->_component];
     if (!empty($manifest->extends)) {
         $this->_request_switch = midcom_baseclasses_components_configuration::get($manifest->extends, 'routes');
     }
     $this->_request_switch = array_merge($this->_request_switch, midcom_baseclasses_components_configuration::get($this->_component, 'routes'));
     $this->_on_initialize();
 }
Пример #27
0
 public static function render_and_attach_pdf(org_openpsa_invoices_invoice_dba $invoice)
 {
     if ($invoice->date == 0 || $invoice->deliverydate == 0) {
         $time = time();
         if ($invoice->date == 0) {
             $invoice->date = $time;
         }
         if ($invoice->deliverydate == 0) {
             $invoice->deliverydate = $time;
         }
         $invoice->update();
     }
     // renders the pdf and attaches it to the invoice
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
     if (!class_exists($client_class)) {
         debug_add('Could not find PDF renderer, aborting silently', MIDCOM_LOG_INFO);
         return false;
     }
     $pdf_builder = new $client_class($invoice);
     // tmp filename
     $tmp_dir = $GLOBALS["midcom_config"]["midcom_tempdir"];
     $title = str_replace("#", "", $invoice->get_label());
     $tmp_file = $tmp_dir . "/" . $title . ".pdf";
     // render pdf to tmp filename
     $render = $pdf_builder->render($tmp_file);
     // cleanup old attachments
     $pdf_files = org_openpsa_helpers::get_attachment_urls($invoice, "pdf_file");
     if (count($pdf_files) > 0) {
         foreach ($pdf_files as $guid => $url) {
             $attachment = new midcom_db_attachment($guid);
             $attachment->delete();
         }
     }
     $attachment = $invoice->create_attachment($title . '.pdf', $title, "application/pdf");
     if (!$attachment) {
         debug_add("Failed to create invoice attachment for pdf", MIDCOM_LOG_ERROR);
         return false;
     }
     $copy = $attachment->copy_from_file($tmp_file);
     if (!$copy) {
         debug_add("Failed to copy pdf from " . $tmp_file . " to attachment", MIDCOM_LOG_ERROR);
         return false;
     }
     // set parameter for datamanager to find the pdf
     if (!$invoice->set_parameter("midcom.helper.datamanager2.type.blobs", "guids_pdf_file", $attachment->guid . ":" . $attachment->guid) || !$attachment->set_parameter('org.openpsa.invoices', 'auto_generated', md5_file($tmp_file))) {
         debug_add("Failed to create attachment parameters, last midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
         return false;
     }
     return true;
 }
Пример #28
0
<?php

$view =& $data['view_deliverable'];
$status = $data['deliverable']->get_status();
$costType = $view['costType'];
$per_unit = $data['l10n']->get('per unit');
try {
    $product = org_openpsa_products_product_dba::get_cached($data['deliverable']->product);
    $unit_options = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('unit_options');
    if (array_key_exists($product->unit, $unit_options)) {
        $unit = midcom::get('i18n')->get_string($unit_options[$product->unit], 'org.openpsa.products');
        $per_unit = sprintf($data['l10n']->get('per %s'), $unit);
    }
} catch (midcom_error $e) {
    $product = false;
    $unit = $data['l10n']->get('unit');
}
?>
<div class="org_openpsa_sales_salesproject_deliverable &(status);">
    <div class="sidebar">
        <div class="contacts area">
            <?php 
echo "<h2>" . $data['l10n']->get('customer') . "</h2>\n";
$customer = $data['salesproject']->get_customer();
echo "<dl>\n<dt>\n" . $customer->render_link() . "</dl>\n</dt>\n";
$contacts = $data['salesproject']->contacts;
foreach ($contacts as $contact_id => $active) {
    $person_card = org_openpsa_widgets_contact::get($contact_id);
    $person_card->show();
}
?>
Пример #29
0
    //TODO: Detect server charset somehow and use that in stead of hardcoded UTF-8
    if (function_exists('mb_detect_encoding') && function_exists('iconv')) {
        //TODO: Should we specify a larger list ?? (apparently we should, auto does not inclide latin1)
        $encoding = strtoupper(mb_detect_encoding($msg, 'ASCII,JIS,UTF-8,ISO-8859-1,EUC-JP,SJIS'));
        debug_add("msg is {$encoding} encoded");
        if ($encoding && ($encoding != 'UTF-8' && $encoding != 'ASCII')) {
            debug_add("converting msg from {$encoding} to UTF-8", MIDCOM_LOG_WARN);
            $stat = iconv($encoding, 'UTF-8', $msg);
            if ($stat) {
                $msg = $stat;
            }
        }
    }
    return $msg;
}
$config = midcom_baseclasses_components_configuration::get('org.routamc.positioning', 'config');
if (array_key_exists('msisdn', $_GET) && $config->get('sms_import_enable')) {
    // We're in SMS mode
    if (!is_null($config->get('sms_import_ip'))) {
        // Check where the request is from
        if ($_SERVER['REMOTE_ADDR'] != $config->get('sms_import_ip')) {
            midcom::get()->finish();
            _midcom_stop_request();
        }
    }
    if (!midcom::get('auth')->request_sudo('org.routamc.positioning')) {
        throw new midcom_error('Could not get sudo rights (check debug log for details)');
    }
    // Find matching person
    $person_qb = midcom_db_person::new_query_builder();
    $person_qb->add_constraint('handphone', '=', "+{$_GET['msisdn']}");
Пример #30
0
 public static function get_widget_config($type)
 {
     $handler_url = midcom_connection::get_url('self') . 'midcom-exec-midcom.helper.datamanager2/autocomplete_handler.php';
     $widget_config = midcom_baseclasses_components_configuration::get('midcom.helper.datamanager2', 'config')->get('clever_classes');
     $config = $widget_config[$type];
     $config['handler_url'] = $handler_url;
     return $config;
 }