public function getTimezoneSelected($account_id) { $criteria = new CDbCriteria(); $criteria->condition = 'Accounts.account_id = 1'; $criteria->params = array(':account_id' => $account_id); return Timezones::model()->with('Accounts')->together()->find($criteria); }
/** * Return timezone object by offset (in seconds) * * Invalid parametar exception will be thrown if timezone with a given offset * does not exist * * @param integer $offset * @return Timezone * @throws InvalidParamError */ function getByOffset($offset) { if (isset($this) && instance_of($this, 'Timezones')) { $name = array_var($this->timezones, $offset); if (is_array($name)) { return new Timezone($offset, implode(', ', $name)); } else { return new InvalidParamError('offset', $offset, "Timezone with offset of {$offset} seconds does not exist"); } // if } else { $instance =& Timezones::instance(); return $instance->getByOffset($offset); } // if }
/** * Render select box for timezone * * Parameters: * * - all HTML attributes * - value - value of selected timezone * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_timezone($params, &$smarty) { $value = array_var($params, 'value', 0, true); $optional = array_var($params, 'optional', true, true); $timezones = Timezones::getAll(); $options = array(); if ($optional) { $options[] = option_tag(lang('-- Select timezone --'), ''); } // if foreach ($timezones as $timezone) { $option_attributes = $value == $timezone->getOffset() ? array('selected' => true) : null; $options[] = option_tag($timezone->__toString(), $timezone->getOffset(), $option_attributes); } // if return select_box($options, $params); }
/** * Process for all begin request application * used to set init aplication timezone */ function begin() { if (!Yii::app()->user->isGuest) { if (Yii::app()->user->getState('timezone_name') == null) { $timezone = Timezones::getTimezoneSelected(Yii::app()->user->Accountid); if (!empty($timezone->timezone_name)) { Yii::app()->user->setState('timezone_name', $timezone->timezone_name); date_default_timezone_set($timezone->timezone_name); } else { Yii::app()->user->setState('timezone_name', Yii::app()->params['timezone']); date_default_timezone_set(Yii::app()->params['timezone']); } } else { date_default_timezone_set(Yii::app()->user->getState('timezone_name')); } } else { date_default_timezone_set(Yii::app()->params['timezone']); } }
<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"> <?php if (form_error('timezone')) { echo "<div class='form-group has-error' >"; } else { echo "<div class='form-group' >"; } ?> <label for="sname" class="col-sm-2 control-label"> <p>Timezone</p> </label> <div class="col-sm-7"> <?php $path = APPPATH . "config/timezones_class.php"; if (@(include $path)) { $timezones_cls = new Timezones(); $timezones = $timezones_cls->get_timezones(); echo form_dropdown("timezone", $timezones, set_value("timezone"), "id='timezone' class='form-control'"); } ?> </div> <span class="col-sm-3 control-label"> <?php echo form_error('timezone'); ?> </span> </div> <div class="form-group"> <div class="row"> <div class="col-sm-4 col-sm-offset-1">
<form action="?step=2" method="POST" class="form-horizontal"> <div class="control-group"> <label class="control-label" for="domain">SMA URL</a></label> <div class="controls"> <input type="text" id="domain" name="domain" class="xlarge" required data-error="SMA URL is required" value="<?php echo "http://" . $_SERVER["SERVER_NAME"] . substr($_SERVER["REQUEST_URI"], 0, -14); ?> " /> </div> </div> <div class="control-group"> <label class="control-label" for="domain">Your Timezone</a></label> <div class="controls"> <?php require_once 'includes/timezones_class.php'; $tz = new Timezones(); $timezones = $tz->get_timezones(); echo '<select name="timezone" required="required" data-error="TimeZone is required">'; foreach ($timezones as $key => $zone) { echo '<option value="' . $key . '">' . $zone . '</option>'; } echo '</select>'; ?> </div> </div> <input type="hidden" name="code" value="<?php echo $_POST['code']; ?> " /> <input type="hidden" name="username" value="<?php echo $_POST['username'];
/** * Render select timezone widget * * @param string $name Name of the select box * @param float $value Timezone value. If NULL GMT will be selected * @param array $attributes Array of additional attributes * @return string */ function select_timezone_widget($name, $value = null, $attributes = null) { $selected_value = (double) $value; $all_timezones = Timezones::getTimezones(); $options = array(); foreach ($all_timezones as $timezone) { $option_attributes = $selected_value == $timezone ? array('selected' => true) : null; $option_text = $timezone > 0 ? lang("timezone gmt +{$timezone}") : lang("timezone gmt {$timezone}"); $options[] = option_tag($option_text, $timezone, $option_attributes); } // if return select_box($name, $options, $attributes); }
/** * Set configuration for localization */ public function actionLocalization() { // check if user has permissions to permissionsConfiguration if (Yii::app()->user->checkAccess('permissionsConfiguration')) { // load actual timezone for account -> Default if not set is America/Mexico_City $model = TimezoneForm::UpdateAccount(); // if TimezoneForm form exist if (isset($_POST['TimezoneForm'])) { // set form elements to TimezoneForm model attributes $model->attributes = $_POST['TimezoneForm']; // timezone is needed if (!empty($model->timezone)) { // update timezone_id from user account $account = Accounts::model()->findByPk(Yii::app()->user->getAccountid()); $account->timezone_id = $model->timezone; // save if ($account->save()) { Yii::app()->user->setFlash('updatedLocalizationSuccess', Yii::t('localization', 'UpdatedMessage')); } } else { // show custom error message $model->addError('timezone', Yii::t('localization', 'timezoneRequired')); } } // set layout page and render content $this->layout = 'column2'; $this->render('assigments/localization', array('model' => $model, 'timezones' => Timezones::model()->findAll())); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
/** * API Method inserts a new Timezones record and render response as JSON */ public function Create() { try { $json = json_decode(RequestUtil::GetBody()); if (!$json) { throw new Exception('The request body does not contain valid JSON'); } $timezones = new Timezones($this->Phreezer); // TODO: any fields that should not be inserted by the user should be commented out // this is an auto-increment. uncomment if updating is allowed // $timezones->Idtimezone = $this->SafeGetVal($json, 'idtimezone'); $timezones->Name = $this->SafeGetVal($json, 'name'); $timezones->Validate(); $errors = $timezones->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $timezones->Save(); $this->RenderJSON($timezones, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }