Example #1
0
/**
 * initializes the invoices module.
 * 
 * @return void
 */
function invoices_init()
{
    global $CONFIG;
    $CONFIG['class_path']['model'][] = __DIR__ . '/invoices/';
    system_load_module("modules/zend.php");
    zend_load("Zend/Pdf.php");
    zend_load("pdf/Cell.php");
    zend_load("pdf/pdfdocument.class.php");
    if (!isset($GLOBALS['VAT_COUNTRIES'])) {
        WdfException::Raise("VAT_COUNTRIES not defined (invoices_init)");
    }
}
 protected function _exportExcel($format = self::EXPORT_FORMAT_XLSX)
 {
     system_load_module(__DIR__ . '/../../../modules/mod_phpexcel.php');
     $xls = new \PHPExcel();
     $sheet = $xls->getActiveSheet();
     $row = 1;
     $max_cell = 0;
     $ci = ExcelCulture::FromCode('en-US');
     $head_rows = $this->_export_get_header();
     $first_data_row = count($head_rows) + 1;
     foreach (array_merge($head_rows, $this->_export_get_data($ci)) as $data_row) {
         $i = 0;
         foreach ($data_row as $val) {
             $sheet->setCellValueByColumnAndRow($i, $row, $val);
             $i++;
             if ($i > $max_cell) {
                 $max_cell = $i;
             }
         }
         $row++;
     }
     for ($i = 0; $i <= $max_cell; $i++) {
         $sheet->getColumnDimensionByColumn($i)->setAutoSize(true);
         if (isset($this->ColFormats[$i])) {
             $ef = $ci->GetExcelFormat($this->ColFormats[$i]);
             $col = \PHPExcel_Cell::stringFromColumnIndex($i);
             $sheet->getStyle("{$col}{$first_data_row}:{$col}{$row}")->getNumberFormat()->setFormatCode($ef);
         }
     }
     if ($format == self::EXPORT_FORMAT_XLS) {
         $xlswriter = \PHPExcel_IOFactory::createWriter($xls, 'Excel5');
     } else {
         $xlswriter = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
     }
     $filename = str_replace("{date}", date("Y-m-d_H-i-s"), self::$export_def[$format]['fn']);
     $mime = self::$export_def[$format]['mime'];
     header("Content-Type: {$mime}");
     header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
     header("Content-Transfer-Encoding: binary");
     header('Expires: 0');
     header('Pragma: public');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header("Cache-Control: private", false);
     $xlswriter->save('php://output');
     die('');
 }
Example #3
0
/**
 * @internal Delayed init method
 */
function globalcache_initialize()
{
    global $CONFIG, $LOCALHOST;
    $ret = true;
    switch ($CONFIG['globalcache']['CACHE']) {
        case globalcache_CACHE_OFF:
        case globalcache_CACHE_APC:
            break;
        case globalcache_CACHE_EACCELERATOR:
            if (!isset($CONFIG['globalcache']['server'])) {
                $CONFIG['globalcache']['server'] = isset($LOCALHOST) ? $LOCALHOST : "localhost";
            }
            break;
        case globalcache_CACHE_MEMCACHE:
            $GLOBALS["memcache_object"] = new Memcache();
            //	$GLOBALS["memcache_object"]->addServer($CONFIG['memcache']['server'], 11211);
            if (!isset($CONFIG['globalcache']['port'])) {
                $CONFIG['globalcache']['port'] = ini_get('memcache.default_port');
            }
            if (!isset($CONFIG['globalcache']['server'])) {
                $CONFIG['globalcache']['server'] = 'localhost';
            }
            $try = 1;
            $tries = 5;
            while ($try++ <= $tries) {
                try {
                    if ($GLOBALS["memcache_object"]->connect($CONFIG['globalcache']['server'], $CONFIG['globalcache']['port'])) {
                        return true;
                    }
                } catch (Exception $ex) {
                }
            }
            if ($try >= $tries) {
                die("globalcache_init unable to connect to memcache server " . $CONFIG['globalcache']['server'] . ":" . $CONFIG['globalcache']['port']);
            }
            break;
        case globalcache_CACHE_ZEND:
            system_load_module("modules/zend.php");
            zend_load("Zend/Cache.php");
            $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 3600, 'write_control' => false, 'cache_id_prefix' => $GLOBALS["globalcache_key_prefix"]);
            $usememcache = extension_loaded('memcache');
            // do we want to store in memcache or in files
            if ($usememcache) {
                $backendOptions = array('servers' => array(array('host' => $CONFIG['globalcache']['server'], 'port' => $CONFIG['globalcache']['port'], 'persistent' => true, 'weight' => 1, 'timeout' => 5, 'retry_interval' => 15, 'status' => true)), 'read_control' => false, 'hashed_directory_level' => 2, 'automatic_cleaning_factor' => 200);
                $GLOBALS["zend_cache_object"] = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
            } else {
                // store data in temp files
                if (isset($CONFIG['model']['ado_cache'])) {
                    $cache_dir = $CONFIG['model']['ado_cache'];
                } else {
                    $cache_dir = sys_get_temp_dir() . "/" . $_SERVER["HTTP_HOST"] . "/";
                }
                if (!is_dir($cache_dir)) {
                    @mkdir($cache_dir);
                }
                if (!is_dir($cache_dir)) {
                    die("globalcache temp dir not found");
                }
                $backendOptions = array('cache_dir' => $cache_dir, 'read_control' => false, 'hashed_directory_level' => 2, 'automatic_cleaning_factor' => 200);
                $GLOBALS["zend_cache_object"] = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
            }
            break;
        case globalcache_CACHE_DB:
            break;
    }
}
Example #4
0
/**
 * Initializes the Scavix ScavixWDF.
 * 
 * This is one of two essential functions you must know about.
 * Initializes the complete ScavixWDF, loads all essentials and defined modules and initializes them,
 * prepares the session and writes out some headers (from config too).
 * @param string $application_name Application name. This will become your session cookie name!
 * @param bool $skip_header Optional. If true, will not send headers.
 * @param bool $logging_category An initial category for logging. Very optional!
 * @return void
 */
function system_init($application_name, $skip_header = false, $logging_category = false)
{
    global $CONFIG;
    $thispath = __DIR__;
    if (!isset($_SESSION["system_internal_cache"])) {
        $_SESSION["system_internal_cache"] = array();
    }
    $CONFIG['system']['application_name'] = $application_name;
    if (!isset($CONFIG['model']['internal']['connection_string'])) {
        $CONFIG['model']['internal']['connection_string'] = 'sqlite::memory:';
    }
    // load essentials as if they were modules.
    system_load_module('essentials/logging.php');
    system_load_module('essentials/model.php');
    system_load_module('essentials/session.php');
    system_load_module('essentials/resources.php');
    system_load_module('essentials/admin.php');
    system_load_module('essentials/localization.php');
    system_load_module('essentials/translation.php');
    foreach (system_glob($thispath . '/essentials/*.php') as $essential) {
        // load all other essentials
        system_load_module($essential);
    }
    if ($logging_category) {
        logging_add_category($logging_category);
    }
    logging_set_user();
    // works as both (session and logging) are now essentials
    session_run();
    // auto-load all system-modules defined in $CONFIG['system']['modules']
    foreach ($CONFIG['system']['modules'] as $mod) {
        if (file_exists($thispath . "/modules/{$mod}.php")) {
            system_load_module($thispath . "/modules/{$mod}.php");
        } elseif (file_exists("{$mod}.php")) {
            system_load_module("{$mod}.php");
        }
    }
    if (isset($_REQUEST['request_id'])) {
        session_keep_alive('request_id');
    }
    // attach more headers here if required
    if (!$skip_header) {
        try {
            foreach ($CONFIG['system']['header'] as $k => $v) {
                header("{$k}: {$v}");
            }
        } catch (Exception $ex) {
        }
    }
    // if $_SERVER['SCRIPT_URI'] is not set build from $_SERVER['SCRIPT_NAME'] and $_SERVER['SERVER_NAME'] Mantis #3477
    if ((!isset($_SERVER['SCRIPT_URI']) || $_SERVER['SCRIPT_URI'] == '') && isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SERVER_NAME'])) {
        $_SERVER['SCRIPT_URI'] = $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
    }
    execute_hooks(HOOK_POST_INIT);
}
 /**
  * Draws text on the curren page.
  * 
  * @param int $x X coordinate
  * @param int $y Y coordinate
  * @param int $font_size Font size
  * @param string $text The text to be drawn
  * @param int $alignment PdfDocument::AL_LEFT, PdfDocument::AL_CENTER or PdfDocument::AL_RIGHT
  * @return int Returns the height of the drawn text (to easily change the $y coordinate for the next call)
  */
 public function drawText($x, $y, $font_size, $text, $alignment = self::AL_LEFT)
 {
     if (!$this->currentPage) {
         $this->currentPage = $this->createNewPage();
     }
     $charEncoding = 'UTF-8';
     $this->currentPage->setFont($this->Font, $font_size);
     $text = trim($text);
     $text = str_ireplace("\r\n", "\n", $text);
     $text = str_ireplace("<br/>", "\n", $text);
     $text = str_ireplace("<br>", "\n", $text);
     $text = str_ireplace("<br />", "\n", $text);
     $text = wordwrap($text, 110, "\n", false);
     switch ($alignment) {
         case self::AL_CENTER:
             $x = $x - $this->textWidth($text, $font_size) / 2;
             break;
         case self::AL_RIGHT:
             $x = $x - $this->textWidth($text, $font_size);
             break;
     }
     // spacial handling for multi-line texts
     if (strpos($text, "\n") !== false) {
         $rows = explode("\n", $text);
         foreach ($rows as $row) {
             $row = str_replace("\r", "", $row);
             $this->currentPage->drawText($row, $x, $y, $charEncoding);
             $y -= 12;
         }
         return $this->LineHeight * count($rows);
     }
     /**
      * Handle Arabic text (mantis #6712)
      */
     if (0 < preg_match('/\\p{Arabic}/u', $text)) {
         system_load_module(__DIR__ . "/../../arabic.php");
         $arglyphs = new I18N_Arabic('Glyphs');
         $text = $arglyphs->utf8Glyphs($text);
     } else {
         if (0 < preg_match('/\\p{Hebrew}/u', $text)) {
             $text = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8//IGNORE", $text)));
         }
     }
     $this->currentPage->drawText($text, $x, $y, $charEncoding);
     return $this->LineHeight;
 }