function run($max_time) {
        foreach (array(
                'registration-staff', 'pwreset-staff', 'banner-staff',
                'registration-client', 'pwreset-client', 'banner-client',
                'registration-confirm', 'registration-thanks',
                'access-link') as $type) {
            $i18n = new Internationalization();
            $tpl = $i18n->getTemplate("templates/page/{$type}.yaml");
            if (!($page = $tpl->getData()))
                // No such template on disk
                continue;

            if ($id = db_result(db_query('select id from '.PAGE_TABLE
                    .' where `type`='.db_input($type))))
                // Already have a template for the content type
                continue;

            $sql = 'INSERT INTO '.PAGE_TABLE.' SET type='.db_input($type)
                .', name='.db_input($page['name'])
                .', body='.db_input($page['body'])
                .', lang='.db_input($tpl->getLang())
                .', notes='.db_input($page['notes'])
                .', created=NOW(), updated=NOW(), isactive=1';
            db_query($sql);
        }
        // Set the content_id for all the new items
        db_query('UPDATE '.PAGE_TABLE
            .' SET `content_id` = `id` WHERE `content_id` = 0');
    }
Example #2
0
 function getTipsJson($namespace, $lang = false)
 {
     global $ost, $thisstaff;
     if (!$lang) {
         $lang = $thisstaff ? $thisstaff->getLanguage() : Internationalization::getDefaultLanguage();
     }
     $i18n = new Internationalization($lang);
     $tips = $i18n->getTemplate("help/tips/{$namespace}.yaml");
     if (!$tips || !($data = $tips->getData())) {
         Http::response(404, 'Help content not available');
     }
     // Translate links to the root path of this installation
     foreach ($data as $tip => &$info) {
         if ($ost) {
             $info = $ost->replaceTemplateVariables($info, array('config' => $ost->getConfig()));
         }
         if (isset($info['links'])) {
             foreach ($info['links'] as &$l) {
                 if ($l['href'][0] == '/') {
                     $l['href'] = ROOT_PATH . substr($l['href'], 1);
                 }
             }
         }
     }
     return $this->json_encode($data);
 }
    function run($max_time) {
        global $cfg;

        $i18n = new Internationalization($cfg->get('system_language', 'en_US'));
        $sequences = $i18n->getTemplate('sequence.yaml')->getData();
        foreach ($sequences as $s) {
            Sequence::create($s)->save();
        }
        db_query('UPDATE '.SEQUENCE_TABLE.' SET `next`= '
            .'(SELECT MAX(ticket_id)+1 FROM '.TICKET_TABLE.') '
            .'WHERE `id`=1');

        require_once(INCLUDE_DIR . 'class.list.php');

        $lists = $i18n->getTemplate('list.yaml')->getData();
        foreach ($lists as $l) {
            DynamicList::create($l);
        }

        $statuses = $i18n->getTemplate('ticket_status.yaml')->getData();
        foreach ($statuses as $s) {
            TicketStatus::__create($s);
        }

        // Initialize MYSQL search backend
        MysqlSearchBackend::__init();
    }
 function run($max_time)
 {
     $i18n = new Internationalization('en_US');
     $forms = $i18n->getTemplate('form.yaml')->getData();
     foreach ($forms as $f) {
         DynamicForm::create($f);
     }
 }
Example #5
0
 function createUpgradedTicket()
 {
     global $cfg;
     $i18n = new Internationalization();
     $vars = $i18n->getTemplate('templates/ticket/upgraded.yaml')->getData();
     $vars['deptId'] = $cfg->getDefaultDeptId();
     //Create a ticket to make the system warm and happy.
     $errors = array();
     Ticket::create($vars, $errors, 'api', false, false);
 }
Example #6
0
 /**
  * Auto-installer. Necessary for 1.8 users between the RC1 release and
  * the stable release who don't have the form in their database because
  * it wan't in the yaml file for installation or upgrade.
  */
 function __loadDefaultForm()
 {
     require_once INCLUDE_DIR . 'class.i18n.php';
     $i18n = new Internationalization();
     $tpl = $i18n->getTemplate('form.yaml');
     foreach ($tpl->getData() as $f) {
         if ($f['type'] == 'C') {
             $form = DynamicForm::create($f);
             $form->save();
             break;
         }
     }
 }
Example #7
0
 function getLanguageFile($lang, $key)
 {
     global $cfg;
     $i18n = new Internationalization($lang);
     switch ($key) {
         case 'js':
             $data = $i18n->getTemplate('js/redactor.js')->getRawData();
             $data .= $i18n->getTemplate('js/jquery.ui.datepicker.js')->getRawData();
             // Strings from various javascript files
             $data .= $i18n->getTemplate('js/osticket-strings.js')->getRawData();
             header('Content-Type: text/javascript; charset=UTF-8');
             break;
         default:
             Http::response(404, 'No such i18n data');
     }
     Http::cacheable(md5($data), $cfg->lastModified());
     echo $data;
 }
 function run($runtime)
 {
     $errors = array();
     $i18n = new Internationalization('en_US');
     $tpls = $i18n->getTemplate('email_template_group.yaml')->getData();
     foreach ($tpls as $t) {
         // If the email template group specifies an id attribute, remove
         // it for upgrade because we cannot assume that the id slot is
         // available
         unset($t['id']);
         EmailTemplateGroup::create($t, $errors);
     }
     $files = $i18n->getTemplate('file.yaml')->getData();
     foreach ($files as $f) {
         $id = AttachmentFile::create($f, $errors);
         // Ensure the new files are never deleted (attached to Disk)
         $sql = 'INSERT INTO ' . ATTACHMENT_TABLE . ' SET object_id=0, `type`=\'D\', inline=1' . ', file_id=' . db_input($id);
         db_query($sql);
     }
 }
Example #9
0
 static function configureForUser($user = false)
 {
     $lang = Internationalization::getCurrentLanguage($user);
     $info = Internationalization::getLanguageInfo(strtolower($lang));
     if (!$info) {
         // Not a supported language
         return;
     }
     // Define locale for C-libraries
     putenv('LC_ALL=' . $info['code']);
     self::setLocale(LC_ALL, $info['code']);
 }
Example #10
0
 function client()
 {
     global $cfg;
     $lang = Internationalization::getCurrentLanguage();
     list($sl, $locale) = explode('_', $lang);
     $rtl = false;
     foreach (Internationalization::availableLanguages() as $info) {
         if (isset($info['direction'])) {
             $rtl = true;
         }
     }
     $config = array('html_thread' => (bool) $cfg->isHtmlThreadEnabled(), 'lang' => $lang, 'short_lang' => $sl, 'has_rtl' => $rtl);
     $config = $this->json_encode($config);
     Http::cacheable(md5($config), $cfg->lastModified());
     header('Content-Type: application/json; charset=UTF-8');
     return $config;
 }
Example #11
0
 function getLanguage()
 {
     static $cached = false;
     if (!$cached) {
         $cached =& $_SESSION['staff:lang'];
     }
     if (!$cached) {
         $cached = $this->config->get('lang');
         if (!$cached) {
             $cached = Internationalization::getDefaultLanguage();
         }
     }
     return $cached;
 }
Example #12
0
 /**
  * Load the template from the initial_data directory. The format of the
  * file should be free flow text. The first line is the subject and the
  * rest of the file is the body.
  */
 function fromInitialData($name, $group = null)
 {
     $templ = new EmailTemplate(0, $group);
     $lang = $group ? $group->getLanguage() : 'en_US';
     $i18n = new Internationalization($lang);
     if (!($tpl = $i18n->getTemplate("templates/email/{$name}.yaml")) || !($info = $tpl->getData())) {
         return false;
     }
     if (isset($info['subject']) && isset($info['body'])) {
         $templ->ht = $info;
         return $templ;
     }
     raise_error("{$lang}/templates/{$name}.yaml: " . _S('Email templates must define both "subject" and "body" parts of the template'), 'InitialDataError');
     return false;
 }
Example #13
0
            </td>
        </tr>
</tbody>
<tbody id="language">
        <tr>
            <td width="180" class="required">
                <?php echo __('Language'); ?>:
            </td>
            <td>
        <?php
        $langs = Internationalization::availableLanguages(); ?>
                <select name="lang_id">
<?php foreach($langs as $l) {
    $selected = ($info['lang_id'] == $l['code']) ? 'selected="selected"' : ''; ?>
                    <option value="<?php echo $l['code']; ?>" <?php echo $selected;
                        ?>><?php echo Internationalization::getLanguageDescription($l['code']); ?></option>
<?php } ?>
                </select>
                &nbsp;<span class="error">*&nbsp;<?php echo $errors['lang_id']; ?></span>
                <i class="help-tip icon-question-sign" href="#language"></i>
            </td>
        </tr>
</tbody>
<tbody>
        <?php } ?>
        <tr>
            <th colspan="2">
                <em><strong><?php echo __('Internal Notes');?></strong>: <?php echo __(
                "be liberal, they're internal");?></em>
            </th>
        </tr>
Example #14
0
 static function __load()
 {
     require_once INCLUDE_DIR . 'class.i18n.php';
     $i18n = new Internationalization();
     $tpl = $i18n->getTemplate('list.yaml');
     foreach ($tpl->getData() as $f) {
         if ($f['type'] == 'ticket-status') {
             $list = DynamicList::create($f);
             $list->save();
             break;
         }
     }
     if (!$list || !($o = DynamicForm::objects()->filter(array('type' => 'L' . $list->getId())))) {
         return false;
     }
     // Create default statuses
     if ($statuses = $i18n->getTemplate('ticket_status.yaml')->getData()) {
         foreach ($statuses as $status) {
             TicketStatus::__create($status);
         }
     }
     return $o[0];
 }
Example #15
0
                </select>
                &nbsp;<span class="error">*&nbsp;<?php 
    echo $errors['tpl_id'];
    ?>
</span><i class="help-tip icon-question-sign" href="#template_to_clone"></i>
            </td>
        </tr>
</tbody>
<tbody id="language">
        <tr>
            <td width="180" class="required">
                Language:
            </td>
            <td>
        <?php 
    $langs = Internationalization::availableLanguages();
    ?>
                <select name="lang_id">
<?php 
    foreach ($langs as $l) {
        $selected = $info['lang_id'] == $l['code'] ? 'selected="selected"' : '';
        ?>
                    <option value="<?php 
        echo $l['code'];
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo $l['desc'];
        ?>
Example #16
0
			),
		),
	"cambriamath" => array(
		'R' => "cambria.ttc",
		'TTCfontID' => array(
			'R' => 2,	
			),
		),
*/
$this->fontdata = array("dejavusanscondensed" => array('R' => "DejaVuSansCondensed.ttf", 'B' => "DejaVuSansCondensed-Bold.ttf", 'I' => "DejaVuSansCondensed-Oblique.ttf", 'BI' => "DejaVuSansCondensed-BoldOblique.ttf"), "dejavusans" => array('R' => "DejaVuSans.ttf", 'B' => "DejaVuSans-Bold.ttf", 'I' => "DejaVuSans-Oblique.ttf", 'BI' => "DejaVuSans-BoldOblique.ttf"), "dejavuserif" => array('R' => "DejaVuSerif.ttf", 'B' => "DejaVuSerif-Bold.ttf", 'I' => "DejaVuSerif-Italic.ttf", 'BI' => "DejaVuSerif-BoldItalic.ttf"), "dejavuserifcondensed" => array('R' => "DejaVuSerifCondensed.ttf", 'B' => "DejaVuSerifCondensed-Bold.ttf", 'I' => "DejaVuSerifCondensed-Italic.ttf", 'BI' => "DejaVuSerifCondensed-BoldItalic.ttf"), "dejavusansmono" => array('R' => "DejaVuSansMono.ttf", 'B' => "DejaVuSansMono-Bold.ttf", 'I' => "DejaVuSansMono-Oblique.ttf", 'BI' => "DejaVuSansMono-BoldOblique.ttf"), "ocrb" => array('R' => "ocrb10.ttf"), "ind_bn_1_001" => array('R' => "ind_bn_1_001.ttf", 'indic' => true), "ind_hi_1_001" => array('R' => "ind_hi_1_001.ttf", 'indic' => true), "ind_ml_1_001" => array('R' => "ind_ml_1_001.ttf", 'indic' => true), "ind_kn_1_001" => array('R' => "ind_kn_1_001.ttf", 'indic' => true), "ind_gu_1_001" => array('R' => "ind_gu_1_001.ttf", 'indic' => true), "ind_or_1_001" => array('R' => "ind_or_1_001.ttf", 'indic' => true), "ind_ta_1_001" => array('R' => "ind_ta_1_001.ttf", 'indic' => true), "ind_te_1_001" => array('R' => "ind_te_1_001.ttf", 'indic' => true), "ind_pa_1_001" => array('R' => "ind_pa_1_001.ttf", 'indic' => true), "xbriyaz" => array('R' => "XB Riyaz.ttf", 'B' => "XB RiyazBd.ttf", 'I' => "XB RiyazIt.ttf", 'BI' => "XB RiyazBdIt.ttf", 'unAGlyphs' => true), "xbzar" => array('R' => "XB Zar.ttf", 'B' => "XB Zar Bd.ttf", 'I' => "XB Zar It.ttf", 'BI' => "XB Zar BdIt.ttf", 'unAGlyphs' => true));
// Add fonts to this array if they contain characters in the SIP or SMP Unicode planes
// but you do not require them. This allows a more efficient form of subsetting to be used.
$this->BMPonly = array("dejavusanscondensed", "dejavusans", "dejavuserifcondensed", "dejavuserif", "dejavusansmono");
// These next 3 arrays do two things:
// 1. If a font referred to in HTML/CSS is not available to mPDF, these arrays will determine whether
//    a serif/sans-serif or monospace font is substituted
// 2. The first font in each array will be the font which is substituted in circumstances as above
//     (Otherwise the order is irrelevant)
// Use the mPDF font-family names i.e. lowercase and no spaces (after any translations in $fonttrans)
// Always include "sans-serif", "serif" and "monospace" etc.
$this->sans_fonts = array('dejavusanscondensed', 'dejavusans', 'freesans', 'liberationsans', 'sans', 'sans-serif', 'cursive', 'fantasy', 'arial', 'helvetica', 'verdana', 'geneva', 'lucida', 'arialnarrow', 'arialblack', 'arialunicodems', 'franklin', 'franklingothicbook', 'tahoma', 'garuda', 'calibri', 'trebuchet', 'lucidagrande', 'microsoftsansserif', 'trebuchetms', 'lucidasansunicode', 'franklingothicmedium', 'albertusmedium', 'xbriyaz', 'albasuper', 'quillscript');
$this->serif_fonts = array('dejavuserifcondensed', 'dejavuserif', 'freeserif', 'liberationserif', 'serif', 'timesnewroman', 'times', 'centuryschoolbookl', 'palatinolinotype', 'centurygothic', 'bookmanoldstyle', 'bookantiqua', 'cyberbit', 'cambria', 'norasi', 'charis', 'palatino', 'constantia', 'georgia', 'albertus', 'xbzar', 'algerian', 'garamond');
$this->mono_fonts = array('dejavusansmono', 'freemono', 'liberationmono', 'courier', 'mono', 'monospace', 'ocrb', 'ocr-b', 'lucidaconsole', 'couriernew', 'monotypecorsiva');
// Add fonts from language packs
list($phar_fonts, $phar_subs) = Internationalization::getTtfFonts();
$this->fontdata += $phar_fonts;
foreach ($phar_subs as $simple) {
    if (!in_array($simple, $this->backupSubsFont)) {
        $this->backupSubsFont[] = $simple;
    }
}
Example #17
0
#start session
session_start();

define('URL',rtrim((Bootstrap::https()?'https':'http').'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']),'setup'));

#define paths
define('INC_DIR',dirname(__file__).'/inc/'); //local include dir!

#required files
require_once(INCLUDE_DIR.'class.setup.php');
require_once(INCLUDE_DIR.'class.validator.php');
require_once(INCLUDE_DIR.'class.passwd.php');
require_once(INCLUDE_DIR.'class.format.php');
require_once(INCLUDE_DIR.'class.misc.php');
require_once INCLUDE_DIR.'mysqli.php';
require_once INCLUDE_DIR.'class.i18n.php';

Internationalization::bootstrap();

// Set browser-preferred language (if installed)
require_once INCLUDE_DIR.'class.translation.php';

// Support flags in the setup portal too
if (isset($_GET['lang']) && $_GET['lang']) {
    $_SESSION['client:lang'] = $_GET['lang'];
}
TextDomain::configureForUser();

?>
Example #18
0
 static function __loadDefaultForm()
 {
     require_once INCLUDE_DIR . 'class.i18n.php';
     $i18n = new Internationalization();
     $tpl = $i18n->getTemplate('form.yaml');
     foreach ($tpl->getData() as $f) {
         if ($f['type'] == 'O') {
             $form = DynamicForm::create($f);
             $form->save();
             break;
         }
     }
     if (!$form || !($o = static::objects())) {
         return false;
     }
     // Create sample organization.
     if ($orgs = $i18n->getTemplate('organization.yaml')->getData()) {
         foreach ($orgs as $org) {
             Organization::__create($org);
         }
     }
     return $o[0];
 }
Example #19
0
        <?php 
    $langs = Internationalization::availableLanguages();
    ?>
                <select name="lang_id">
<?php 
    foreach ($langs as $l) {
        $selected = $info['lang_id'] == $l['code'] ? 'selected="selected"' : '';
        ?>
                    <option value="<?php 
        echo $l['code'];
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo Internationalization::getLanguageDescription($l['code']);
        ?>
</option>
<?php 
    }
    ?>
                </select>
                &nbsp;<span class="error">*&nbsp;<?php 
    echo $errors['lang_id'];
    ?>
</span>
                <i class="help-tip icon-question-sign" href="#language"></i>
            </td>
        </tr>
</tbody>
<tbody>
Example #20
0
 function getLanguage()
 {
     static $cached = false;
     if (!$cached) {
         $cached =& $_SESSION['client:lang'];
     }
     if (!$cached) {
         if ($acct = $this->getAccount()) {
             $cached = $acct->getLanguage();
         }
         if (!$cached) {
             $cached = Internationalization::getDefaultLanguage();
         }
     }
     return $cached;
 }
Example #21
0
 function start()
 {
     // Prep basic translation support
     Internationalization::bootstrap();
     if (!($ost = new osTicket())) {
         return null;
     }
     //Set default time zone... user/staff settting will override it (on login).
     $_SESSION['TZ_OFFSET'] = $ost->getConfig()->getTZoffset();
     $_SESSION['TZ_DST'] = $ost->getConfig()->observeDaylightSaving();
     // Bootstrap installed plugins
     $ost->plugins->bootstrap();
     // Mirror content updates to the search backend
     $ost->searcher = new SearchInterface();
     return $ost;
 }
Example #22
0
if (!in_array(strtolower(basename($_SERVER['SCRIPT_NAME'])), array('logo.php', 'file.php')) && !(is_object($ost) && $ost->isSystemOnline())) {
    include ROOT_DIR . 'offline.php';
    exit;
}
/* include what is needed on client stuff */
require_once INCLUDE_DIR . 'class.client.php';
require_once INCLUDE_DIR . 'class.ticket.php';
require_once INCLUDE_DIR . 'class.dept.php';
//clear some vars
$errors = array();
$msg = '';
$nav = null;
//Make sure the user is valid..before doing anything else.
$thisclient = UserAuthenticationBackend::getUser();
if (isset($_GET['lang']) && $_GET['lang']) {
    if (Internationalization::getLanguageInfo($_GET['lang'])) {
        $_SESSION['client:lang'] = $_GET['lang'];
    }
}
// Bootstrap gettext translations as early as possible, but after attempting
// to sign on the agent
TextDomain::configureForUser($thisclient);
//is the user logged in?
if ($thisclient && $thisclient->getId() && $thisclient->isValid()) {
    $thisclient->refreshSession();
} else {
    $thisclient = null;
}
/******* CSRF Protectin *************/
// Enforce CSRF protection for POSTS
if ($_POST && !$ost->checkCSRFToken()) {
Example #23
0
<?php

header("Content-Type: text/html; charset=UTF-8");
if (!isset($_SERVER['HTTP_X_PJAX'])) {
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html <?php 
    if (($lang = Internationalization::getCurrentLanguage()) && ($info = Internationalization::getLanguageInfo($lang)) && @$info['direction'] == 'rtl') {
        echo 'dir="rtl" class="rtl"';
    }
    ?>
>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="x-pjax-version" content="<?php 
    echo GIT_VERSION;
    ?>
">
    <title><?php 
    echo $ost && ($title = $ost->getPageTitle()) ? $title : 'osTicket :: ' . __('Staff Control Panel');
    ?>
</title>
    <!--[if IE]>
    <style type="text/css">
        .tip_shadow { display:block !important; }
    </style>
    <![endif]-->
    <script type="text/javascript" src="<?php 
Example #24
0
        <div id="header">
            <img id="logo" src="./images/<?php echo $wizard['logo']?$wizard['logo']:'logo.png'; ?>" width="280" height="72" alt="osTicket">
            <div class="info"><?php echo $wizard['tagline']; ?></div>
            <br/>
            <ul class="links">
                <li>
                   <?php
                   foreach($wizard['menu'] as $k=>$v)
                    echo sprintf('<a target="_blank" href="%s">%s</a> &mdash; ',$v,$k);
                   ?>
                    <a target="_blank" href="http://osticket.com/contact-us"><?php echo __('Contact Us');?></a>
                </li>
            </ul>
            <div class="flags">
<?php
if (($all_langs = Internationalization::availableLanguages())
    && (count($all_langs) > 1)
) {
    foreach ($all_langs as $code=>$info) {
        list($lang, $locale) = explode('_', $code);
?>
        <a class="flag flag-<?php echo strtolower($locale ?: $info['flag'] ?: $lang); ?>"
            href="?<?php echo urlencode($_GET['QUERY_STRING']); ?>&amp;lang=<?php echo $code;
            ?>" title="<?php echo Internationalization::getLanguageDescription($code); ?>">&nbsp;</a>
<?php }
} ?>
            </div>
        </div>
        <div class="clear"></div>
        <div id="content">
Example #25
0
    function install($vars) {

        $this->errors=$f=array();

        $f['name']          = array('type'=>'string',   'required'=>1, 'error'=>__('Name required'));
        $f['email']         = array('type'=>'email',    'required'=>1, 'error'=>__('Valid email required'));
        $f['fname']         = array('type'=>'string',   'required'=>1, 'error'=>__('First name required'));
        $f['lname']         = array('type'=>'string',   'required'=>1, 'error'=>__('Last name required'));
        $f['admin_email']   = array('type'=>'email',    'required'=>1, 'error'=>__('Valid email required'));
        $f['username']      = array('type'=>'username', 'required'=>1, 'error'=>__('Username required'));
        $f['passwd']        = array('type'=>'password', 'required'=>1, 'error'=>__('Password required'));
        $f['passwd2']       = array('type'=>'password', 'required'=>1, 'error'=>__('Confirm Password'));
        $f['prefix']        = array('type'=>'string',   'required'=>1, 'error'=>__('Table prefix required'));
        $f['dbhost']        = array('type'=>'string',   'required'=>1, 'error'=>__('Host name required'));
        $f['dbname']        = array('type'=>'string',   'required'=>1, 'error'=>__('Database name required'));
        $f['dbuser']        = array('type'=>'string',   'required'=>1, 'error'=>__('Username required'));
        $f['dbpass']        = array('type'=>'string',   'required'=>1, 'error'=>__('Password required'));

        $vars = array_map('trim', $vars);

        if(!Validator::process($f,$vars,$this->errors) && !$this->errors['err'])
            $this->errors['err']=__('Missing or invalid data - correct the errors and try again.');


        //Staff's email can't be same as system emails.
        if($vars['admin_email'] && $vars['email'] && !strcasecmp($vars['admin_email'],$vars['email']))
            $this->errors['admin_email']=__('Conflicts with system email above');
        //Admin's pass confirmation.
        if(!$this->errors && strcasecmp($vars['passwd'],$vars['passwd2']))
            $this->errors['passwd2']=__('Password(s) do not match');
        //Check table prefix underscore required at the end!
        if($vars['prefix'] && substr($vars['prefix'], -1)!='_')
            $this->errors['prefix']=__('Bad prefix. Must have underscore (_) at the end. e.g \'ost_\'');

        //Make sure admin username is not very predictable. XXX: feels dirty but necessary
        if(!$this->errors['username'] && in_array(strtolower($vars['username']),array('admin','admins','username','osticket')))
            $this->errors['username']=__('Bad username');

        // Support port number specified in the hostname with a colon (:)
        list($host, $port) = explode(':', $vars['dbhost']);
        if ($port && is_numeric($port) && ($port < 1 || $port > 65535))
            $this->errors['db'] = __('Invalid database port number');

        //MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!)
        if(!$this->errors) {
            if(!db_connect($vars['dbhost'],$vars['dbuser'],$vars['dbpass']))
                $this->errors['db']=sprintf(__('Unable to connect to MySQL server: %s'), db_connect_error());
            elseif(explode('.', db_version()) < explode('.', $this->getMySQLVersion()))
                $this->errors['db']=sprintf(__('osTicket requires MySQL %s or later!'),$this->getMySQLVersion());
            elseif(!db_select_database($vars['dbname']) && !db_create_database($vars['dbname'])) {
                $this->errors['dbname']=__("Database doesn't exist");
                $this->errors['db']=__('Unable to create the database.');
            } elseif(!db_select_database($vars['dbname'])) {
                $this->errors['dbname']=__('Unable to select the database');
            } else {
                //Abort if we have another installation (or table) with same prefix.
                $sql = 'SELECT * FROM `'.$vars['prefix'].'config` LIMIT 1';
                if(db_query($sql, false)) {
                    $this->errors['err'] = __('We have a problem - another installation with same table prefix exists!');
                    $this->errors['prefix'] = __('Prefix already in-use');
                } else {
                    //Try changing charset and collation of the DB - no bigie if we fail.
                    db_query('ALTER DATABASE '.$vars['dbname'].' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci', false);
                }
            }
        }

        //bailout on errors.
        if($this->errors) return false;

        /*************** We're ready to install ************************/
        define('ADMIN_EMAIL',$vars['admin_email']); //Needed to report SQL errors during install.
        define('TABLE_PREFIX',$vars['prefix']); //Table prefix
        Bootstrap::defineTables(TABLE_PREFIX);
        Bootstrap::loadCode();

        $debug = true; // Change it to false to squelch SQL errors.

        //Last minute checks.
        if(!file_exists($this->getConfigFile()) || !($configFile=file_get_contents($this->getConfigFile())))
            $this->errors['err']=__('Unable to read config file. Permission denied! (#2)');
        elseif(!($fp = @fopen($this->getConfigFile(),'r+')))
            $this->errors['err']=__('Unable to open config file for writing. Permission denied! (#3)');

        else {
            $streams = DatabaseMigrater::getUpgradeStreams(INCLUDE_DIR.'upgrader/streams/');
            foreach ($streams as $stream=>$signature) {
                $schemaFile = INC_DIR."streams/$stream/install-mysql.sql";
                if (!file_exists($schemaFile) || !($fp2 = fopen($schemaFile, 'rb')))
                    $this->errors['err'] = sprintf(
                        __('%s: Internal Error - please make sure your download is the latest (#1)'),
                        $stream);
                elseif (
                        // TODO: Make the hash algo configurable in the streams
                        //       configuration ( core : md5 )
                        !($hash = md5(fread($fp2, filesize($schemaFile))))
                        || strcasecmp($signature, $hash))
                    $this->errors['err'] = sprintf(
                        __('%s: Unknown or invalid schema signature (%s .. %s)'),
                        $stream,
                        $signature, $hash);
                elseif (!$this->load_sql_file($schemaFile, $vars['prefix'], true, $debug))
                    $this->errors['err'] = sprintf(
                        __('%s: Error parsing SQL schema! Get help from developers (#4)'),
                        $stream);
            }
        }

        if(!$this->errors) {

            // TODO: Use language selected from install worksheet
            $i18n = new Internationalization($vars['lang_id']);
            $i18n->loadDefaultData();

            Signal::send('system.install', $this);

            $sql='SELECT `id` FROM '.TABLE_PREFIX.'sla ORDER BY `id` LIMIT 1';
            $sla_id_1 = db_result(db_query($sql, false));

            $sql='SELECT `dept_id` FROM '.TABLE_PREFIX.'department ORDER BY `dept_id` LIMIT 1';
            $dept_id_1 = db_result(db_query($sql, false));

            $sql='SELECT `tpl_id` FROM '.TABLE_PREFIX.'email_template_group ORDER BY `tpl_id` LIMIT 1';
            $template_id_1 = db_result(db_query($sql, false));

            $sql='SELECT `group_id` FROM '.TABLE_PREFIX.'groups ORDER BY `group_id` LIMIT 1';
            $group_id_1 = db_result(db_query($sql, false));

            $sql='SELECT `value` FROM '.TABLE_PREFIX.'config WHERE namespace=\'core\' and `key`=\'default_timezone_id\' LIMIT 1';
            $default_timezone = db_result(db_query($sql, false));

            //Create admin user.
            $sql='INSERT INTO '.TABLE_PREFIX.'staff SET created=NOW() '
                .", isactive=1, isadmin=1, group_id='$group_id_1', dept_id='$dept_id_1'"
                .", timezone_id='$default_timezone', max_page_size=25"
                .', email='.db_input($vars['admin_email'])
                .', firstname='.db_input($vars['fname'])
                .', lastname='.db_input($vars['lname'])
                .', username='******'username'])
                .', passwd='.db_input(Passwd::hash($vars['passwd']));
            if(!db_query($sql, false) || !($uid=db_insert_id()))
                $this->errors['err']=__('Unable to create admin user (#6)');
        }

        if(!$this->errors) {
            //Create default emails!
            $email = $vars['email'];
            list(,$domain)=explode('@',$vars['email']);
            $sql='INSERT INTO '.TABLE_PREFIX.'email (`name`,`email`,`created`,`updated`) VALUES '
                    ." ('Support','$email',NOW(),NOW())"
                    .",('osTicket Alerts','alerts@$domain',NOW(),NOW())"
                    .",('','noreply@$domain',NOW(),NOW())";
            $support_email_id = db_query($sql, false) ? db_insert_id() : 0;


            $sql='SELECT `email_id` FROM '.TABLE_PREFIX."email WHERE `email`='alerts@$domain' LIMIT 1";
            $alert_email_id = db_result(db_query($sql, false));

            //Create config settings---default settings!
            $defaults = array(
                'default_email_id'=>$support_email_id,
                'alert_email_id'=>$alert_email_id,
                'default_dept_id'=>$dept_id_1, 'default_sla_id'=>$sla_id_1,
                'default_template_id'=>$template_id_1,
                'admin_email'=>$vars['admin_email'],
                'schema_signature'=>$streams['core'],
                'helpdesk_url'=>URL,
                'helpdesk_title'=>$vars['name']);
            $config = new Config('core');
            if (!$config->updateAll($defaults))
                $this->errors['err']=__('Unable to create config settings').' (#7)';

            // Set company name
            require_once(INCLUDE_DIR.'class.company.php');
            $company = new Company();
            $company->getForm()->setAnswer('name', $vars['name']);
            $company->getForm()->save();

			foreach ($streams as $stream=>$signature) {
				if ($stream != 'core') {
                    $config = new Config($stream);
                    if (!$config->update('schema_signature', $signature))
                        $this->errors['err']=__('Unable to create config settings').' (#8)';
				}
			}
        }

        if($this->errors) return false; //Abort on internal errors.


        //Rewrite the config file - MUST be done last to allow for installer recovery.
        $configFile= str_replace("define('OSTINSTALLED',FALSE);","define('OSTINSTALLED',TRUE);",$configFile);
        $configFile= str_replace('%ADMIN-EMAIL',$vars['admin_email'],$configFile);
        $configFile= str_replace('%CONFIG-DBHOST',$vars['dbhost'],$configFile);
        $configFile= str_replace('%CONFIG-DBNAME',$vars['dbname'],$configFile);
        $configFile= str_replace('%CONFIG-DBUSER',$vars['dbuser'],$configFile);
        $configFile= str_replace('%CONFIG-DBPASS',$vars['dbpass'],$configFile);
        $configFile= str_replace('%CONFIG-PREFIX',$vars['prefix'],$configFile);
        $configFile= str_replace('%CONFIG-SIRI',Misc::randCode(32),$configFile);
        if(!$fp || !ftruncate($fp,0) || !fwrite($fp,$configFile)) {
            $this->errors['err']=__('Unable to write to config file. Permission denied! (#5)');
            return false;
        }
        @fclose($fp);

        /************* Make the system happy ***********************/

        $sql='UPDATE '.TABLE_PREFIX."email SET dept_id=$dept_id_1";
        db_query($sql, false);

        global $cfg;
        $cfg = new OsticketConfig();

        //Create a ticket to make the system warm and happy.
        $errors = array();
        $ticket_vars = $i18n->getTemplate('templates/ticket/installed.yaml')
            ->getData();
        $ticket = Ticket::create($ticket_vars, $errors, 'api', false, false);

        if ($ticket
                && ($org = Organization::objects()->order_by('id')->one())) {

            $user=User::lookup($ticket->getOwnerId());
            $user->setOrganization($org);
        }

        //TODO: create another personalized ticket and assign to admin??

        //Log a message.
        $msg=__("Congratulations osTicket basic installation completed!\n\nThank you for choosing osTicket!");
        $sql='INSERT INTO '.TABLE_PREFIX.'syslog SET created=NOW(), updated=NOW(), log_type="Debug" '
            .', title="osTicket installed!"'
            .', log='.db_input($msg)
            .', ip_address='.db_input($_SERVER['REMOTE_ADDR']);
        db_query($sql, false);

        return true;
    }
Example #26
0
?>
</a>
    </div>
<div id="overlay"></div>
<div id="loading">
    <h4><?php 
echo __('Please Wait!');
?>
</h4>
    <p><?php 
echo __('Please wait... it will take a second!');
?>
</p>
</div>
<?php 
if (($lang = Internationalization::getCurrentLanguage()) && $lang != 'en_US') {
    ?>
    <script type="text/javascript" src="ajax.php/i18n/<?php 
    echo $lang;
    ?>
/js"></script>
<?php 
}
?>
</body>
<script>
//Tell the window to respond to the width, along with the whole middle part.
jQuery("div#container").css("width","100%");// dynamic width to fit into the screen.
jQuery("table").attr('width', "100%"); //now that that has been resized, we need to make sure the th's fit within it.
jQuery(".message th:nth-child(1)").attr('width',"20%");
<?php if (!isset($_SERVER['HTTP_X_PJAX'])) { ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html <?php
if (($lang = Internationalization::getCurrentLanguage())
        && ($info = Internationalization::getLanguageInfo($lang))
        && (@$info['direction'] == 'rtl'))
    echo 'dir="rtl" class="rtl"';
?>>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="x-pjax-version" content="<?php echo GIT_VERSION; ?>">
    <title><?php echo ($ost && ($title=$ost->getPageTitle()))?$title:'osTicket :: '.__('Staff Control Panel'); ?></title>
    <!--[if IE]>
    <style type="text/css">
        .tip_shadow { display:block !important; }
    </style>
    <![endif]-->
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery-1.8.3.min.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery-ui-1.10.3.custom.min.js?c18eac4"></script>
    <script type="text/javascript" src="./js/scp.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.pjax.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/filedrop.field.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/jquery.multiselect.min.js?c18eac4"></script>
    <script type="text/javascript" src="./js/tips.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor.min.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor-osticket.js?c18eac4"></script>
    <script type="text/javascript" src="<?php echo ROOT_PATH; ?>js/redactor-fonts.js?c18eac4"></script>
    <script type="text/javascript" src="./js/bootstrap-typeahead.js?c18eac4"></script>
Example #28
0
if (($all_langs = Internationalization::availableLanguages()) && count($all_langs) > 1) {
    foreach ($all_langs as $code => $info) {
        list($lang, $locale) = explode('_', $code);
        ?>
        <a class="flag flag-<?php 
        echo strtolower($locale ?: $info['flag'] ?: $lang);
        ?>
"
            href="?<?php 
        echo urlencode($_GET['QUERY_STRING']);
        ?>
&amp;lang=<?php 
        echo $code;
        ?>
" title="<?php 
        echo Internationalization::getLanguageDescription($code);
        ?>
">&nbsp;</a>
<?php 
    }
}
?>
            </p>
            </div>
            <a class="pull-left" id="logo" href="<?php 
echo ROOT_PATH;
?>
index.php"
            title="<?php 
echo __('Support Center');
?>
        $space = db_result(db_query($sql));
        echo sprintf('%.2f MiB', $space); ?></td>
    <tr><td><?php echo __('Space for Attachments'); ?></td>
        <td><?php
        $sql = 'SELECT SUM(LENGTH(filedata)) / 1048576 FROM '.FILE_CHUNK_TABLE;
        $space = db_result(db_query($sql));
        echo sprintf('%.2f MiB', $space); ?></td>
</tbody>
</table>
<br/>
<h2><?php echo __('Installed Language Packs'); ?></h2>
<div style="margin: 0 20px">
<?php
    foreach (Internationalization::availableLanguages() as $info) {
        $p = $info['path'];
        if ($info['phar']) $p = 'phar://' . $p;
        if (file_exists($p . '/MANIFEST.php')) {
            $manifest = (include $p . '/MANIFEST.php'); ?>
    <h3><strong><?php echo Internationalization::getLanguageDescription($info['code']); ?></strong>
        &mdash; <?php echo $manifest['Language']; ?>
<?php       if ($info['phar'])
                Plugin::showVerificationBadge($info['path']);
            ?>
        </h3>
        <div><?php echo __('Version'); ?>: <?php echo $manifest['Version']; ?>,
            <?php echo __('Built'); ?>: <?php echo $manifest['Build-Date']; ?>
        </div>
<?php }
    } ?>
</div>