/**
  * Convert display date for saving to model
  *
  * @returns JSON encoded HTML output
  */
 public function actionConvert()
 {
     $output = '';
     $module = Yii::$app->controller->module;
     $post = Yii::$app->request->post();
     if (isset($post['displayDate'])) {
         $type = empty($post['type']) ? Module::FORMAT_DATE : $post['type'];
         $saveFormat = ArrayHelper::getValue($post, 'saveFormat');
         $dispFormat = ArrayHelper::getValue($post, 'dispFormat');
         $dispTimezone = ArrayHelper::getValue($post, 'dispTimezone');
         $saveTimezone = ArrayHelper::getValue($post, 'saveTimezone');
         if ($dispTimezone != null) {
             $date = DateTime::createFromFormat($dispFormat, $post['displayDate'], new DateTimeZone($dispTimezone));
         } else {
             $date = DateTime::createFromFormat($dispFormat, $post['displayDate']);
         }
         if (empty($date) || !$date) {
             $value = '';
         } elseif ($saveTimezone != null) {
             $date->setTimezone(new DateTimeZone($saveTimezone))->format($saveFormat);
         } else {
             $value = $date->format($saveFormat);
         }
         echo Json::encode(['status' => 'success', 'output' => $value]);
     } else {
         echo Json::encode(['status' => 'error', 'output' => 'No display date found']);
     }
 }
Beispiel #2
0
 /**
  * Generates the JavaScript with the specified client changes.
  * @param string $event event name (without 'on')
  * @param array $htmlOptions HTML attributes which may contain the following special attributes
  * specifying the client change behaviors:
  * <ul>
  * <li>submit: string, specifies the URL to submit to. If the current element has a parent form, that form will be
  * submitted, and if 'submit' is non-empty its value will replace the form's URL. If there is no parent form the
  * data listed in 'params' will be submitted instead (via POST method), to the URL in 'submit' or the currently
  * requested URL if 'submit' is empty. Please note that if the 'csrf' setting is true, the CSRF token will be
  * included in the params too.</li>
  * <li>params: array, name-value pairs that should be submitted together with the form. This is only used when 'submit' option is specified.</li>
  * <li>csrf: boolean, whether a CSRF token should be automatically included in 'params' when {@link CHttpRequest::enableCsrfValidation} is true. Defaults to false.
  * You may want to set this to be true if there is no enclosing form around this element.
  * This option is meaningful only when 'submit' option is set.</li>
  * <li>return: boolean, the return value of the javascript. Defaults to false, meaning that the execution of
  * javascript would not cause the default behavior of the event.</li>
  * <li>confirm: string, specifies the message that should show in a pop-up confirmation dialog.</li>
  * <li>ajax: array, specifies the AJAX options (see {@link ajax}).</li>
  * <li>live: boolean, whether the event handler should be delegated or directly bound.
  * If not set, {@link liveEvents} will be used. This option has been available since version 1.1.11.</li>
  * </ul>
  * @see http://www.yiiframework.com/doc/api/1.1/CHtml/#clientChange-detail
  */
 public static function clientChange($event, &$htmlOptions)
 {
     if (!isset($htmlOptions['submit']) && !isset($htmlOptions['confirm']) && !isset($htmlOptions['ajax'])) {
         return;
     }
     $live = ArrayHelper::getValue($htmlOptions, 'live', static::$liveEvents);
     $return = isset($htmlOptions['return']) && $htmlOptions['return'] ? 'return true' : 'return false';
     if (isset($htmlOptions['on' . $event])) {
         $handler = trim($htmlOptions['on' . $event], ';') . ';';
         unset($htmlOptions['on' . $event]);
     } else {
         $handler = '';
     }
     if (isset($htmlOptions['id'])) {
         $id = $htmlOptions['id'];
     } else {
         $id = $htmlOptions['id'] = isset($htmlOptions['name']) ? $htmlOptions['name'] : CHtml::ID_PREFIX . CHtml::$count++;
     }
     $cs = \Yii::app()->getClientScript();
     $cs->registerCoreScript('jquery');
     if (isset($htmlOptions['submit'])) {
         $cs->registerCoreScript('yii');
         $request = \Yii::app()->getRequest();
         if ($request->enableCsrfValidation && isset($htmlOptions['csrf']) && $htmlOptions['csrf']) {
             $htmlOptions['params'][$request->csrfTokenName] = $request->getCsrfToken();
         }
         if (isset($htmlOptions['params'])) {
             $params = \CJavaScript::encode($htmlOptions['params']);
         } else {
             $params = '{}';
         }
         if ($htmlOptions['submit'] !== '') {
             $url = \CJavaScript::quote(\CHtml::normalizeUrl($htmlOptions['submit']));
         } else {
             $url = '';
         }
         $handler .= ";jQuery.yii.submitForm(this,'{$url}',{$params});{$return};";
     }
     if (isset($htmlOptions['ajax'])) {
         $handler .= \CHtml::ajax($htmlOptions['ajax']) . "{$return};";
     }
     if (isset($htmlOptions['confirm'])) {
         $confirm = 'confirm(\'' . \CJavaScript::quote($htmlOptions['confirm']) . '\')';
         if ($handler !== '') {
             $handler = "if({$confirm}) {" . $handler . "} else return false;";
         } else {
             $handler = "return {$confirm};";
         }
     }
     if ($live) {
         $cs->registerScript('Foundation.Html.#' . $id, "jQuery('body').on('{$event}','#{$id}',function(){{$handler}});");
     } else {
         $cs->registerScript('Foundation.Html.#' . $id, "jQuery('#{$id}').on('{$event}', function(){{$handler}});");
     }
     $htmlOptions = ArrayHelper::removeKeys($htmlOptions, array('params', 'submit', 'ajax', 'confirm', 'return', 'csrf'));
 }
Beispiel #3
0
 /**
  * Constructor
  *
  * @param   array $config A named configuration array for object construction.
  *
  */
 public function __construct($config = array())
 {
     $this->app = ArrayHelper::getValue($config, 'app', JFactory::getApplication());
     $this->user = ArrayHelper::getValue($config, 'user', JFactory::getUser());
     $this->package = $this->app->getUserState('com_fabrik.package', 'fabrik');
     $this->session = ArrayHelper::getValue($config, 'session', JFactory::getSession());
     $this->doc = ArrayHelper::getValue($config, 'doc', JFactory::getDocument());
     $this->db = ArrayHelper::getValue($config, 'db', JFactory::getDbo());
     $this->config = ArrayHelper::getValue($config, 'config', JFactory::getConfig());
     parent::__construct($config);
 }
Beispiel #4
0
 protected function renderFooterCellContentJS($model)
 {
     $key = '';
     if ($this->value !== null) {
         if (is_string($this->value)) {
             return ArrayHelper::getValue($model, $this->value);
         } else {
             return call_user_func($this->value, $model, '', '', $this);
         }
     } elseif ($this->attribute !== null) {
         $this->filterInputOptions['style'] = 'width:100%;';
         return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error;
     }
     return null;
 }
Beispiel #5
0
 /**
  * Sets default options
  */
 protected function defaultOptions()
 {
     parent::defaultOptions();
     unset($this->clientOptions['imageUpload']);
     unset($this->clientOptions['fileUpload']);
     unset($this->clientOptions['imageManagerJson']);
     unset($this->clientOptions['fileManagerJson']);
     if (isset($this->clientOptions['plugins']) && array_search('imagemanager', $this->clientOptions['plugins']) !== false) {
         $this->setOptionsKey('imageUpload', $this->module->imageUploadRoute);
         $this->clientOptions['imageUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'imageUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
         $this->setOptionsKey('imageManagerJson', $this->module->imageManagerJsonRoute);
     }
     if (isset($this->clientOptions['plugins']) && array_search('filemanager', $this->clientOptions['plugins']) !== false) {
         $this->setOptionsKey('fileUpload', $this->module->fileUploadRoute);
         $this->clientOptions['fileUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'fileUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
         $this->setOptionsKey('fileManagerJson', $this->module->fileManagerJsonRoute);
     }
 }
Beispiel #6
0
 protected function renderFooterCellContentJS($model)
 {
     $key = '';
     if ($this->value !== null) {
         if (is_string($this->value)) {
             return ArrayHelper::getValue($model, $this->value);
         } else {
             return call_user_func($this->value, $model, '', '', $this);
         }
     } elseif ($this->attribute !== null) {
         $html = '<a id="thumb-image-\'+data.id+\'" class="img-thumbnail" href="/index.php?r=catalog%2Fadmin%2Fupdate&amp;id=17" data-toggle="image">';
         $html .= Html::img(\andreosoft\image\Image::thumb($model[$this->attribute], 100, 100), ['data-placeholder' => \andreosoft\image\Image::thumb('', 100, 100)]);
         $html .= '</a>';
         $html .= '<input type="hidden" id="input-image-\'+data.id+\'" name="' . \yii\helpers\BaseHtml::getInputName($model, $this->attribute) . '">';
         return $html;
     }
     return null;
 }
 /**
  * Parses current view request with ability to match custom slugs
  * appropriate AR model
  */
 protected function parseViewRequest($manager, $request)
 {
     // gets all request params
     $params = ArrayHelper::getValue(parent::parseRequest($manager, $request), 1);
     // if there is no params in current request this rule will not match
     if ($params) {
         // finds model by current slug
         $model = \frontend\models\db\MyBasic::find()->andWhere([\frontend\models\db\MyBasic::tablename() . '.slug' => ArrayHelper::getValue($params, 'post')])->one();
         // if model is not found this rule will not match
         if (!$model) {
             return false;
         }
         // get appropriate route
         $route = \frontend\components\helpers\url\routes\MyBasicRouteHelper::view($model);
         // gets default route name & params
         $name = \frontend\components\helpers\url\routes\MyBasicRouteHelper::getName($route);
         $params = \frontend\components\helpers\url\routes\MyBasicRouteHelper::getParams($route);
         // retrieves mathced route
         return [$name, $params];
     }
     return false;
 }
Beispiel #8
0
 protected function _getValue($property, $keyS = null, $default = null)
 {
     return ArrayHelper::getValue($this->_properties, $keyS ? "{$property}.{$keyS}" : $property, $default);
 }
Beispiel #9
0
?>
</title>
    <?php 
$this->head();
?>
    <?php 
echo Html::csrfMetaTags();
?>
</head>
<body>
<?php 
$this->beginBody();
?>
        <?php 
if (Yii::$app->session->hasFlash('alert')) {
    ?>
            <?php 
    echo \yii\bootstrap\Alert::widget(['body' => ArrayHelper::getValue(Yii::$app->session->getFlash('alert'), 'body'), 'options' => ArrayHelper::getValue(Yii::$app->session->getFlash('alert'), 'options')]);
    ?>
        <?php 
}
?>
        <?php 
echo $content;
$this->endBody();
?>

</body>
</html>
<?php 
$this->endPage();
Beispiel #10
0
function checksubmit($var = 'submit', $allowget = false)
{
    global $_W, $_GPC;
    if (empty($_GPC[$var])) {
        return false;
    }
    return request()->validateCsrfToken(ArrayHelper::getValue($_GPC, 'token'));
}
Beispiel #11
0
 public static function renderSelectOptions($selection, $items, &$tagOptions = [])
 {
     $lines = [];
     $encodeSpaces = ArrayHelper::remove($tagOptions, 'encodeSpaces', false);
     $encode = ArrayHelper::remove($tagOptions, 'encode', true);
     if (isset($tagOptions['prompt'])) {
         $prompt = $encode ? static::encode($tagOptions['prompt']) : $tagOptions['prompt'];
         if ($encodeSpaces) {
             $prompt = str_replace(' ', '&nbsp;', $prompt);
         }
         $lines[] = static::tag('option', $prompt, ['value' => '']);
     }
     $options = isset($tagOptions['options']) ? $tagOptions['options'] : [];
     $groups = isset($tagOptions['groups']) ? $tagOptions['groups'] : [];
     unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
     $options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
     $options['encode'] = ArrayHelper::getValue($options, 'encode', $encode);
     foreach ($items as $key => $value) {
         if (is_array($value)) {
             $groupAttrs = isset($groups[$key]) ? $groups[$key] : [];
             if (!isset($groupAttrs['label'])) {
                 $groupAttrs['label'] = $key;
             }
             $attrs = ['options' => $options, 'groups' => $groups, 'encodeSpaces' => $encodeSpaces, 'encode' => $encode];
             $content = static::renderSelectOptions($selection, $value, $attrs);
             $lines[] = static::tag('optgroup', "\n" . $content . "\n", $groupAttrs);
         } else {
             $attrs = isset($options[$key]) ? $options[$key] : [];
             $attrs['value'] = (string) $key;
             $attrs['selected'] = $selection !== null && (!is_array($selection) && !strcmp($key, $selection) || is_array($selection) && in_array($key, $selection));
             $text = $encode ? static::encode($value) : $value;
             if ($encodeSpaces) {
                 $text = str_replace(' ', '&nbsp;', $text);
             }
             $lines[] = static::tag('option', $text, $attrs);
         }
     }
     return implode("\n", $lines);
 }
Beispiel #12
0
 /**
  * Generic function to redirect
  *
  * @param   object  &$model  form model
  * @param   string  $msg     redirection message to show
  *
  * @return  string  redirect url
  */
 protected function makeRedirect(&$model, $msg = null)
 {
     $app = JFactory::getApplication();
     $package = $app->getUserState('com_fabrik.package', 'fabrik');
     $input = $app->input;
     $formId = $input->getInt('formid');
     $listId = $input->getInt('listid');
     $rowId = $input->getString('rowid', '', 'string');
     if (is_null($msg)) {
         $msg = FText::_('COM_FABRIK_RECORD_ADDED_UPDATED');
     }
     if ($app->isAdmin()) {
         // Admin option is always com_fabrik
         if (array_key_exists('apply', $model->formData)) {
             $url = 'index.php?option=com_fabrik&c=form&task=form&formid=' . $formId . '&listid=' . $listId . '&rowid=' . $rowId;
         } else {
             $url = 'index.php?option=com_fabrik&c=table&task=viewTable&cid[]=' . $model->getTable()->id;
         }
         $this->setRedirect($url, $msg);
     } else {
         if (array_key_exists('apply', $model->formData)) {
             $url = 'index.php?option=com_' . $package . '&c=form&view=form&formid=' . $formId . '&rowid=' . $rowId . '&listid=' . $listId;
         } else {
             if ($this->isMambot) {
                 // Return to the same page
                 $url = filter_var(ArrayHelper::getValue($_SERVER, 'REQUEST_URI', 'index.php'), FILTER_SANITIZE_URL);
             } else {
                 // Return to the page that called the form
                 $url = $input->get('fabrik_referrer', 'index.php', 'string');
             }
             $itemId = FabrikWorker::itemId();
             if ($url == '') {
                 $url = 'index.php?option=com_' . $package . '&Itemid=' . $itemId;
             }
         }
         $config = JFactory::getConfig();
         if ($config->get('sef')) {
             $url = JRoute::_($url);
         }
         $this->setRedirect($url, $msg);
     }
 }
Beispiel #13
0
 public function getStatusName()
 {
     return ArrayHelper::getValue(self::getStatusesArray(), $this->status);
 }
Beispiel #14
0
 public static function map($objects, $params)
 {
     $result = [];
     foreach ($objects as $object) {
         $objectParams = [];
         foreach ($params as $from => $to) {
             $objectParams[$to] = ArrayHelper::getValue($object, $from);
         }
         $result[] = $objectParams;
     }
     return $result;
 }
Beispiel #15
0
 /**
  * Generates a bootstrap toggle button group (checkbox or radio type)
  * 
  * @param string $type whether checkbox or radio.
  * @param string $name the name attribute of each checkbox.
  * @param string|array $selection the selected value(s).
  * @param array $items the data item used to generate the checkboxes/radios.
  * The array keys are the checkbox/radio values, while the array values are the corresponding labels.
  * @param array $options options (name => config) for the checkbox/radio list container tag.
  * The following options are specially handled:
  *
  * - tag: string, the tag name of the container element.
  * - unselect: string, the value that should be submitted when none of the checkboxes/radios is selected.
  *   By setting this option, a hidden input will be generated.
  * - encode: boolean, whether to HTML-encode the checkbox/radio labels. Defaults to true.
  *   This option is ignored if `item` option is set.
  * - separator: string, the HTML code that separates items.
  * - itemOptions: array, the options for generating the checkbox/radio tag using [[checkbox/radio()]].
  * - item: callable, a callback that can be used to customize the generation of the HTML code
  *   corresponding to a single item in $items. The signature of this callback must be:
  *
  *   ~~~
  *   function ($index, $label, $name, $checked, $value)
  *   ~~~
  *
  *   where $index is the zero-based index of the checkbox/radio in the whole list; $label
  *   is the label for the checkbox/radio; and $name, $value and $checked represent the name,
  *   value and the checked status of the checkbox/radio input, respectively.
  *
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  *
  * @return string the generated toggle button group
  */
 public static function getButtonGroup($type, $name, $selection = null, $items = [], $options = [])
 {
     $class = $type . 'List';
     static::addCssClass($options, 'btn-group');
     $options['data-toggle'] = 'buttons';
     $options['inline'] = true;
     if (!isset($options['itemOptions']['labelOptions']['class'])) {
         $options['itemOptions']['labelOptions']['class'] = 'btn btn-default';
     }
     $options['item'] = function ($index, $label, $name, $checked, $value) use($type, $options) {
         $opts = isset($options['itemOptions']) ? $options['itemOptions'] : [];
         $encode = !isset($options['encode']) || $options['encode'];
         if (!isset($opts['labelOptions'])) {
             $opts['labelOptions'] = ArrayHelper::getValue($options, 'itemOptions.labelOptions', []);
         }
         if ($checked) {
             Html::addCssClass($opts['labelOptions'], 'active');
         }
         return static::$type($name, $checked, array_merge($opts, ['value' => $value, 'label' => $encode ? static::encode($label) : $label]));
     };
     return static::$class($name, $selection, $items, $options);
 }
 public function actionRelease($id)
 {
     //$model = $this->findModel($id);
     $model = new Pendingdoc();
     $userid = ArrayHelper::getValue(Document::find()->where(['id' => $id])->one(), 'user_id');
     $userFName = ArrayHelper::getValue(User::find()->where(['id' => $userid])->one(), 'userFName');
     $userLName = ArrayHelper::getValue(User::find()->where(['id' => $userid])->one(), 'userLName');
     $section = ArrayHelper::getValue(Document::find()->where(['id' => $id])->one(), 'section_id');
     $documentname = ArrayHelper::getValue(Document::find()->where(['id' => $id])->one(), 'documentName');
     if ($model->load(Yii::$app->request->post())) {
         $model->pendingDocFName = $userFName . $userLName;
         $model->pendingDocSection = $section;
         $model->pendingDocName = $documentname;
         if ($model->save()) {
             return $this->redirect(['document/index']);
         }
     } else {
         return $this->renderAjax('release', ['model' => $model]);
     }
 }