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}/"; }
/** * 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); }
public function __get($field) { if (array_key_exists($field, $this->_services)) { return $this->_services[$field]; } $instance = null; switch ($field) { case '_i18n': $instance = midcom::get('i18n'); break; case '_l10n': $instance = midcom::get('i18n')->get_l10n($this->_component); break; case '_l10n_midcom': $instance = midcom::get('i18n')->get_l10n('midcom'); break; case '_config': $instance = midcom_baseclasses_components_configuration::get($this->_component, 'config'); break; default: debug_add('Component ' . $this->_component . ' tried to access nonexistant service "' . $field . '"', MIDCOM_LOG_ERROR); debug_print_function_stack('Called from here:'); return false; } $this->_services[$field] = $instance; return $this->_services[$field]; }
/** */ 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; }
/** * 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; }
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); }
/** * 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(); }
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']); }
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'); }
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); }
/** * 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; }
public function get_plugin_handlers() { $handlers = midcom_baseclasses_components_configuration::get($this->_component, 'routes'); return $handlers; }
<?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
/** * 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'); }
/** * Helper function to record failed login attempts and disable account is necessary * * @param string $component the component we take the config values from * @return boolean True if further login attempts are allowed, false otherwise */ public function check_login_attempts($component = null) { $stat = true; if (is_null($component)) { $component = "org.openpsa.user"; } //max-attempts allowed & timeframe $max_attempts = midcom_baseclasses_components_configuration::get($component, 'config')->get('max_password_attempts'); $timeframe = midcom_baseclasses_components_configuration::get($component, 'config')->get('password_block_timeframe_min'); if ($max_attempts == 0 || $timeframe == 0) { return $stat; } midcom::get('auth')->request_sudo('org.openpsa.user'); $attempts = $this->_person->get_parameter("org_openpsa_user_password", "attempts"); if (!empty($attempts)) { $attempts = unserialize($attempts); if (is_array($attempts)) { $attempts = array_slice($attempts, 0, $max_attempts - 1); } } if (!is_array($attempts)) { $attempts = array(); } array_unshift($attempts, time()); /* * If the maximum number of attemps is reached and the oldest attempt * on the stack is within our defined timeframe, we block the account */ if (sizeof($attempts) >= $max_attempts && $attempts[$max_attempts - 1] >= time() - $timeframe * 60) { $this->disable_account(); $stat = false; } $attempts = serialize($attempts); $this->_person->set_parameter("org_openpsa_user_password", "attempts", $attempts); midcom::get('auth')->drop_sudo(); return $stat; }
/** * 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(); }
<?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(); } ?>
public function generate_invoice_number() { $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator'); $calculator = new $client_class(); return $calculator->generate_invoice_number(); }
//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']}");
<?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();
<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);
/** * 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; }
public static function get_config_value($value) { $config = midcom_baseclasses_components_configuration::get('org.openpsa.widgets', 'config'); return $config->get($value); }
public function load_schemadb() { $schemadb_name = midcom_baseclasses_components_configuration::get('org.openpsa.relatedto', 'config')->get('schemadb_journalentry'); return midcom_helper_datamanager2_schema::load_database($schemadb_name); }
/** * 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(); } } }
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; }
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; }
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(); }
/** * 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']; }
/** * Loads and prepares a delete controller. Any error triggers a 500. * * @return midcom_helper_datamanager2_controller_nullstorage The delete controller */ public static function get_delete_controller() { $controller = midcom_helper_datamanager2_controller::create('nullstorage'); $delete_schemadb = midcom_baseclasses_components_configuration::get('midcom.helper.datamanager2', 'config')->get('schemadb_delete'); $controller->schemadb = midcom_helper_datamanager2_schema::load_database($delete_schemadb); if (!$controller->initialize()) { throw new midcom_error("Failed to initialize a DM2 controller instance for object {$object->guid}."); } return $controller; }