Example #1
0
 /**
  * Creates a new Dashboard card with the $id dashboard_card_{ID_HERE}
  * $id is a randomly generated hash based upon the unique data of the card.json + name, and contains 2 key pieces of information
  *     1) The class name
  *     2) The path in.dot.format
  *
  * Once created, the unique instance is added to the user's specific dashboard. This is an Ajax specific request
  * @param  string  $id  The unique id of the card as defined on creation of said card type
  * @return bool
  */
 public function actionAdd($id)
 {
     if ($id == NULL) {
         throw new CHttpException(400, Yii::t('Dashboard.main', 'An ID must be specified'));
     }
     $config = Configuration::model()->findByAttributes(array('key' => $id));
     if ($config == NULL) {
         throw new CHttpException(400, Yii::t('Dashboard.main', 'No card type exists with that ID'));
     }
     $name = CJSON::decode($config->value);
     Yii::import($name['path'] . '.*');
     $card = new $name['class']();
     $card->create($id, $name['path']);
     $data = CJSON::decode($card->getJSON($name['path']));
     $data['id'] = $card->id;
     // Update the user's card information
     $meta = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'dashboard'));
     if ($meta == NULL) {
         $meta = new UserMetadata();
         $meta->key = 'dashboard';
         $meta->user_id = Yii::app()->user->id;
         $meta->value = array();
     }
     if (!is_array($meta->value)) {
         $order = CJSON::decode($meta->value);
     } else {
         $order = $meta->value;
     }
     $order[] = $card->id;
     $meta->value = CJSON::encode($order);
     $meta->save();
     return $card->render();
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Configuration the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Configuration::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #3
0
 /**
  * Bypasses our [param] file and loads key directly from database.
  *
  * Necessary for the NextOrderID as well
  * as LSKEY Soap calls
  *
  * @param string $strKey Key name.
  *
  * @return bool|CActiveRecord
  */
 public static function loadByKey($strKey)
 {
     $obj = Configuration::model()->findByAttributes(array('key_name' => $strKey));
     if ($obj) {
         return $obj;
     }
     return false;
 }
 public function actionIndex()
 {
     $model = Configuration::model()->findByPk(1);
     if (isset($_POST['Configuration'])) {
         $model->attributes = $_POST['Configuration'];
         if ($model->save()) {
             $this->redirect(array('config/index'));
         }
     }
     $this->render('index', array('model' => $model));
 }
Example #5
0
 public function canUserBid($userId)
 {
     $config = CHtml::listData(Configuration::model()->findAll(array('select' => 'name, value')), 'name', 'value');
     $criteria = new CDbCriteria();
     $criteria->condition = "fk_user =  {$userId} AND DATE(created_at) = CURDATE() ";
     $bidCount = $this->count($criteria);
     if (isset($config['max_bid_count']) && $bidCount >= $config['max_bid_count']) {
         return false;
     } elseif ($bidCount >= self::DEFAULT_MAX_BID_COUNT) {
         return false;
     }
     return true;
 }
 public static function initParams()
 {
     defined('DEFAULT_THEME') or define('DEFAULT_THEME', 'brooklyn2014');
     $params = CHtml::listData(Configuration::model()->findAll(), 'key_name', 'key_value');
     foreach ($params as $key => $value) {
         Yii::app()->params->add($key, $value);
     }
     if (isset(Yii::app()->params['THEME'])) {
         Yii::app()->theme = Yii::app()->params['THEME'];
     } else {
         Yii::app()->theme = DEFAULT_THEME;
     }
     if (isset(Yii::app()->params['LANG_CODE'])) {
         Yii::app()->language = Yii::app()->params['LANG_CODE'];
     } else {
         Yii::app()->language = "en";
     }
     Yii::app()->params->add('listPerPage', Yii::app()->params['PRODUCTS_PER_PAGE']);
     //Based on logging setting, set log level dynamically and possibly turn on debug mode
     switch (Yii::app()->params['DEBUG_LOGGING']) {
         case 'info':
             $logLevel = "error,warning,info";
             break;
         case 'trace':
             $logLevel = "error,warning,info,trace";
             defined('YII_DEBUG') or define('YII_DEBUG', true);
             defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
             break;
         case 'error':
         default:
             $logLevel = "error,warning";
             break;
     }
     foreach (Yii::app()->getComponent('log')->routes as $route) {
         $route->levels = $logLevel;
     }
     Yii::app()->setViewPath(Yii::getPathOfAlias('application') . "/views-cities");
     Yii::app()->name = Yii::app()->params['STORE_NAME'];
     if (Yii::app()->params['LIGHTSPEED_CLOUD'] == '-1') {
         //We should never see this, this means our cloud cache file is bad
         $strHostfile = realpath(dirname(__FILE__)) . '/../../../config/cloud/' . $_SERVER['HTTP_HOST'] . ".php";
         @unlink($strHostfile);
         Yii::app()->request->redirect(Yii::app()->createUrl('site/index'));
     }
 }
 /**
  * Short Description.
  *
  * @return void
  */
 public function actionEdit()
 {
     $id = Yii::app()->getRequest()->getQuery('id');
     $model = Configuration::model()->findAllByAttributes(array('configuration_type_id' => $id), array('order' => 'sort_order'));
     if ($this->IsCloud) {
         $model = $this->sanitizeEditModule($model, 'Cloud');
     }
     if ($this->IsMT) {
         $model = $this->sanitizeEditModule($model, 'MT');
     }
     if ($this->isHosted) {
         $model = $this->sanitizeEditModule($model, 'Hosted');
     }
     if (isset($_POST['Configuration'])) {
         $valid = true;
         foreach ($model as $i => $item) {
             if (isset($_POST['Configuration'][$i])) {
                 $item->attributes = $_POST['Configuration'][$i];
             }
             if ($item->key_name == 'LANG_MENU' && $item->key_value == 1) {
                 $itemLanguages = $model[2];
                 $itemLanguages->attributes = $_POST['Configuration'][2];
                 if (empty($itemLanguages->key_value)) {
                     $valid = false;
                 }
             }
             if ($item->options == "INT") {
                 if ((int) $item->key_value) {
                     $valid = true;
                 } else {
                     $valid = false;
                 }
             }
             if ($item->options == "EMAIL") {
                 $valid = $this->validateEmail($item) && $valid;
             } else {
                 $valid = $item->validate() && $valid;
             }
             if (!$valid) {
                 if ($item->options == 'EMAIL') {
                     Yii::app()->user->setFlash('error', $item->title . ' is not a valid email address');
                 } elseif ($item->key_name == 'LANG_MENU') {
                     Yii::app()->user->setFlash('error', 'Languages field cannot be empty when language menu is enabled');
                 } elseif ($item->options == "INT") {
                     Yii::app()->user->setFlash('error', $item->title . ': ' . 'Only numbers are allowed', true);
                 } else {
                     $err = $item->getErrors();
                     Yii::app()->user->setFlash('error', $item->title . ' -- ' . print_r($err['key_value'][0], true));
                 }
                 break;
             }
         }
         if ($valid) {
             foreach ($model as $i => $item) {
                 $item->attributes = $_POST['Configuration'][$i];
                 if ($item->options == "PASSWORD") {
                     $item->key_value = _xls_encrypt($item->key_value);
                 }
                 if ($item->save() === false) {
                     Yii::app()->user->setFlash('error', print_r($item->getErrors(), true));
                 } else {
                     Yii::app()->user->setFlash('success', Yii::t('admin', 'Configuration updated on {time}.', array('{time}' => date('d F, Y  h:i:sa'))));
                     $item->postConfigurationChange();
                 }
                 if ($item->key_name == 'EMAIL_TEST' && $item->key_value == 1) {
                     $this->sendEmailTest();
                 }
             }
         }
     }
     foreach ($model as $i => $item) {
         if ($item->options == 'BOOL') {
             $this->registerOnOff($item->id, "Configuration_{$i}_key_value", $item->key_value);
         }
         if ($item->options == 'PASSWORD') {
             $model[$i]->key_value = _xls_decrypt($model[$i]->key_value);
         }
         $model[$i]->title = Yii::t('admin', $item->title, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
         $model[$i]->helper_text = Yii::t('admin', $item->helper_text, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
     }
     /*
      * http://www.yiiframework.com/doc/api/1.1/CModel#generateAttributeLabel-detail
      *
      * Unless we define the label attribute in activeLabelEx htmlOptions in the view,
      * the label will be generated when it calls CModel::generateAttributeLabel().
      * This is a problem for the labels we want to display on pages like the Google Integration
      * page that have labels which deliberately require dashes and camel-case formatting.
      */
     $defineLabel = false;
     switch (CPropertyValue::ensureInteger($id)) {
         case 20:
             // IntegrationController::GOOGLE = 20
             $defineLabel = true;
             break;
         default:
             break;
     }
     $this->render('admin.views.default.edit', array('model' => $model, 'defineLabel' => $defineLabel));
 }
 protected function loadDefaults($strTheme)
 {
     $arrKeys = array();
     $objComponent = Yii::app()->getComponent('wstheme');
     $model = $objComponent->getAdminModel($strTheme);
     if ($model) {
         $formname = $strTheme . "AdminForm";
         $arrKeys = get_class_vars($formname);
         $form = new $formname();
         $themeVersion = $form->version;
     } else {
         //If we don't have a CForm definition, we have to go old school
         //(that means look for config.xml for backwards compatibility)
         $fnOptions = self::getConfigFile($strTheme);
         if (file_exists($fnOptions)) {
             $strXml = file_get_contents($fnOptions);
             // Parse xml for response values
             $oXML = new SimpleXMLElement($strXml);
             if ($oXML->defaults) {
                 foreach ($oXML->defaults->{'configuration'} as $item) {
                     $keyname = (string) $item->key_name;
                     $keyvalue = (string) $item->key_value;
                     $arrKeys[$keyname] = $keyvalue;
                 }
             }
             $themeVersion = $oXML->version;
         }
     }
     //Now we have an array of keys no matter which method
     foreach ($arrKeys as $keyname => $keyvalue) {
         $objKey = Configuration::model()->findByAttributes(array('key_name' => $keyname));
         if ($objKey) {
             _xls_set_conf($keyname, $keyvalue);
             Configuration::model()->updateByPk($objKey->id, array('template_specific' => '1'));
         }
     }
     return array($arrKeys, $themeVersion);
 }
 public function actionEdit()
 {
     $id = Yii::app()->getRequest()->getQuery('id');
     $model = Configuration::model()->findAllByAttributes(array('configuration_type_id' => $id), array('order' => 'sort_order'));
     if (isset($_POST['Configuration'])) {
         $valid = true;
         foreach ($model as $i => $item) {
             if (isset($_POST['Configuration'][$i])) {
                 $item->attributes = $_POST['Configuration'][$i];
             }
             $valid = $item->validate() && $valid;
             if (!$valid) {
                 $err = $item->getErrors();
                 Yii::app()->user->setFlash('error', $item->title . " -- " . print_r($err['key_value'][0], true));
                 break;
             }
         }
         if ($valid) {
             foreach ($model as $i => $item) {
                 $item->attributes = $_POST['Configuration'][$i];
                 if ($item->options == "PASSWORD") {
                     $item->key_value = _xls_encrypt($item->key_value);
                 }
                 if (!$item->save()) {
                     Yii::app()->user->setFlash('error', print_r($item->getErrors(), true));
                 } else {
                     $item->postConfigurationChange();
                 }
                 if ($item->key_name == 'EMAIL_TEST' && $item->key_value == 1) {
                     $this->sendEmailTest();
                 }
             }
             Yii::app()->user->setFlash('success', Yii::t('admin', 'Configuration updated on {time}.', array('{time}' => date("d F, Y  h:i:sa"))));
         }
     }
     foreach ($model as $i => $item) {
         if ($item->key_name == "EMAIL_TEST") {
             $item->key_value = 0;
         }
         if ($item->options == "BOOL") {
             $this->registerOnOff($item->id, "Configuration_{$i}_key_value", $item->key_value);
         }
         if ($item->options == "PASSWORD") {
             $model[$i]->key_value = _xls_decrypt($model[$i]->key_value);
         }
         $model[$i]->title = Yii::t('admin', $item->title, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
         $model[$i]->helper_text = Yii::t('admin', $item->helper_text, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check')));
     }
     $this->render('edit', array('model' => $model));
 }
Example #10
0
 /**
  * Deletes a card and all associated files from the system
  * @param  string $id The id of the card we want to delete
  * @return boolean    If the card was deleted or not
  */
 public function actionDeleteCard($id = NULL)
 {
     if ($id == NULL) {
         throw new CHttpException(400, Yii::t('Dashboard.main', 'You must specify a card to delete'));
     }
     $card = Configuration::model()->findByAttributes(array('key' => $id));
     if ($card == NULL) {
         throw new CHttpException(400, Yii::t('Dashboard.main', 'There are no dashboard cards with that id'));
     }
     $card->value = CJSON::decode($card->value);
     return $card->fullDelete($card->value['folderName']);
 }
Example #11
0
function _xls_insert_conf($key, $title, $value, $helperText, $configType, $options, $sortOrder = NULL, $templateSpecific = 0)
{
    $conf = Configuration::LoadByKey($key);
    if (!$conf) {
        $conf = new Configuration();
    }
    $conf->key_name = $key;
    $conf->title = $title;
    $conf->key_value = $value;
    $conf->helper_text = $helperText;
    $conf->configuration_type_id = $configType;
    $conf->options = $options;
    $query = <<<EOS
\t\tSELECT IFNULL(MAX(sortOrder),0)+1
\t\tFROM xlsws_configuration
\t\tWHERE configuration_type_id = '{$configType}';
EOS;
    if (!$sortOrder) {
        $sortOrder = Configuration::model()->findBySql($query);
    }
    $conf->sort_order = $sortOrder;
    $conf->template_specific = $templateSpecific;
    $conf->created = new CDbExpression('NOW()');
    $conf->modified = new CDbExpression('NOW()');
    if (!$conf->save()) {
        print_r($conf->getErrors());
    }
}