コード例 #1
0
ファイル: function.atktext.php プロジェクト: sintattica/atk
/**
 * function to get multilanguage strings.
 *
 * This is actually a wrapper for ATK's Tools::atktext() method, for
 * use in templates.
 *
 * @author Ivo Jansch <*****@*****.**>
 *
 * Example: {atktext id="users.userinfo.description"}
 *          {atktext id="userinfo.description" module="users"}
 *          {atktext id="description" module="users" node="userinfo"}
 */
function smarty_function_atktext($params, $smarty)
{
    if (!isset($params['id'])) {
        $params['id'] = $params[0];
    }
    switch (substr_count($params['id'], '.')) {
        case 1:
            list($module, $id) = explode('.', $params['id']);
            $str = Tools::atktext($id, $module, isset($params['node']) ? $params['node'] : '');
            break;
        case 2:
            list($module, $node, $id) = explode('.', $params['id']);
            $str = Tools::atktext($id, $module, $node);
            break;
        default:
            $str = Tools::atktext($params['id'], Tools::atkArrayNvl($params, 'module', ''), Tools::atkArrayNvl($params, 'node', ''), Tools::atkArrayNvl($params, 'lng', ''));
    }
    if (isset($params['filter'])) {
        $fn = $params['filter'];
        $str = $fn($str);
    }
    // parse the rest of the params in the string
    $parser = new StringParser($str);
    return $parser->parse($params);
}
コード例 #2
0
ファイル: TreeNode.php プロジェクト: sintattica/atk
 /**
  * Build the tree.
  *
  * @return TreeToolsTree Tree object
  */
 public function buildTree()
 {
     Tools::atkdebug('treenode::buildtree() ' . $this->m_parent);
     $recordset = $this->select(Tools::atkArrayNvl($this->m_postvars, 'atkfilter', ''))->excludes($this->m_listExcludes)->mode('admin')->getAllRows();
     $treeobject = new TreeToolsTree();
     for ($i = 0; $i < count($recordset); ++$i) {
         $treeobject->addNode($recordset[$i][$this->m_primaryKey[0]], $recordset[$i], $recordset[$i][$this->m_parent][$this->m_primaryKey[0]]);
     }
     return $treeobject;
 }
コード例 #3
0
ファイル: FileExport.php プロジェクト: sintattica/atk
 /**
  * Export data to a download file.
  *
  * BROWSER BUG:
  * IE has problems with the use of attachment; needs atachment (someone at MS can't spell) or none.
  * however ns under version 6 accepts this also.
  * NS 6+ has problems with the absense of attachment; and the misspelling of attachment;
  * at present ie 5 on mac gives wrong filename and NS 6+ gives wrong filename.
  *
  * @todo Currently supports only csv/excel mimetypes.
  *
  * @param string $data The content
  * @param string $fileName Filename for the download
  * @param string $type The type (csv / excel / xml)
  * @param string $ext Extension of the file
  * @param string $compression Compression method (bzip / gzip)
  */
 public function export($data, $fileName, $type, $ext = '', $compression = '')
 {
     ob_end_clean();
     if ($compression == 'bzip') {
         $mime_type = 'application/x-bzip';
         $ext = 'bz2';
     } elseif ($compression == 'gzip') {
         $mime_type = 'application/x-gzip';
         $ext = 'gz';
     } elseif ($type == 'csv') {
         $mime_type = 'text/x-csv';
         $ext = 'csv';
     } elseif ($type == 'excel') {
         $mime_type = 'application/octet-stream';
         $ext = 'xls';
     } elseif ($type == 'xml') {
         $mime_type = 'text/xml';
         $ext = 'xml';
     } else {
         $mime_type = 'application/octet-stream';
     }
     header('Content-Type: ' . $mime_type);
     header('Content-Disposition:  filename="' . $fileName . '.' . $ext . '"');
     // Fix for downloading (Office) documents using an SSL connection in
     // combination with MSIE.
     if (($_SERVER['SERVER_PORT'] == '443' || Tools::atkArrayNvl($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') && preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) {
         header('Pragma: public');
     } else {
         header('Pragma: no-cache');
     }
     header('Expires: 0');
     // 1. as a bzipped file
     if ($compression == 'bzip') {
         if (@function_exists('bzcompress')) {
             echo bzcompress($data);
         }
     } else {
         if ($compression == 'gzip') {
             if (@function_exists('gzencode')) {
                 // without the optional parameter level because it bug
                 echo gzencode($data);
             }
         } else {
             if ($type == 'csv' || $type == 'excel') {
                 // in order to output UTF-8 content that Excel both on Windows and OS X will be able to successfully read
                 echo mb_convert_encoding($data, 'Windows-1252', 'UTF-8');
             }
         }
     }
     flush();
     exit;
 }
コード例 #4
0
ファイル: DurationAttribute.php プロジェクト: sintattica/atk
 /**
  * Returns a piece of html code that can be used in a form to edit this
  * attribute's value. (hours, minutes and seconds will be a dropdownbox).
  *
  * @param array $record The record that holds the value for this attribute.
  * @param string $fieldprefix The fieldprefix to put in front of the name
  *                            of any html form element for this attribute.
  * @param string $mode The mode we're in ('add' or 'edit')
  *
  * @return string Piece a of HTML Code
  */
 public function edit($record, $fieldprefix, $mode)
 {
     $id = $this->getHtmlId($fieldprefix);
     $fieldvalue = Tools::atkArrayNvl($record, $this->fieldName(), '');
     if (!$this->hasFlag(self::AF_DURATION_STRING)) {
         $curminutes = null;
         $result = '<div class="form-inline">';
         if ($this->m_maxtime_min >= 60) {
             $curhours = $this->_getHourPart($fieldvalue);
             $curminutes = $this->_getMinutePart($fieldvalue);
             $result .= '<select id="' . $id . '_hours" name="' . $this->getHtmlName($fieldprefix) . '[hours]" class="form-control select-standard">';
             for ($h = 0; $h <= $this->m_maxtime_min / 60;) {
                 $result .= '<option value="' . $h . '" ';
                 if ($curhours == $h) {
                     $result .= 'selected';
                 }
                 $result .= '>' . $h . ' ' . Tools::atktext('hours', 'atk');
                 if ($this->m_resolution_min <= 60) {
                     ++$h;
                 } else {
                     $h = floor($h + $this->m_resolution_min / 60);
                 }
             }
             $result .= '</select>';
         }
         if ($this->m_maxtime_min >= 1 && $this->m_resolution_min < 60) {
             $result .= '&nbsp;<select id="' . $id . '_minutes" name="' . $this->getHtmlName($fieldprefix) . '[minutes]" class="form-control select-standard">';
             for ($m = 0; $m < 60 || $this->m_maxtime_min < 60 && $m < $this->m_maxtime_min;) {
                 $result .= '<option value="' . $m . '" ';
                 if ($curminutes == $m) {
                     $result .= 'selected';
                 }
                 $result .= '>' . $m . ' ' . Tools::atktext('minutes', 'atk');
                 if ($this->m_resolution_min <= 1) {
                     ++$m;
                 } else {
                     $m = $m + $this->m_resolution_min;
                 }
             }
             $result .= '</select>';
         }
         $result .= '</div>';
     } else {
         $curval = $fieldvalue > 0 ? $this->_minutes2string($fieldvalue) : '';
         $result = '<input type="text" name="' . $this->getHtmlName($fieldprefix) . '" value="' . $curval . '"' . ($this->m_size > 0 ? ' size="' . $this->m_size . '"' : '') . '>';
     }
     return $result;
 }
コード例 #5
0
ファイル: Statement.php プロジェクト: sintattica/atk
 /**
  * Get rows in an associative array with the given key column used as
  * key and the given value column used as value.
  *
  * NOTE:
  * This is not an efficient way to retrieve records, as this will load all
  * records into an array in memory. If you retrieve a lot of records, you
  * are better of using Statement::getIterator which only retrieves one
  * row at a time.
  *
  * Depending on the database driver, using this method multiple times might
  * result in the query to be executed multiple times.
  *
  * @param int|string $keyColumn column index / name (default first column) to be used as key
  * @param int|string $valueColumn column index / name (default first column) to be used as value
  *
  * @return array rows
  */
 public function getAllValuesAssoc($keyColumn = 0, $valueColumn = 1)
 {
     $rows = $this->getAllRowsAssoc($keyColumn);
     foreach ($rows as $key => &$value) {
         if (is_numeric($valueColumn)) {
             $value = Tools::atkArrayNvl(array_values($value), $valueColumn);
         } else {
             $value = $value[$valueColumn];
         }
     }
     return $rows;
 }
コード例 #6
0
ファイル: PasswordAttribute.php プロジェクト: sintattica/atk
 /** Due to the new storeType functions
  * password field is not allways saved from within the password attrib.
  *
  * Added a "dynamic" needsUpdate to cancel updates if no password fields where used
  * to alter the password. This overcomes the overwriting with an empty password.
  *
  * @param array $record The record that contains this attribute's value
  *
  * @return bool
  */
 public function needsUpdate($record)
 {
     $value = $record[$this->fieldName()];
     // new is set from an update using the password attrib edit() function
     if (Tools::atkArrayNvl($value, 'new', '') != '' || Tools::atkArrayNvl($value, 'hash', '') != '') {
         return true;
     }
     return false;
 }
コード例 #7
0
ファイル: DeleteHandler.php プロジェクト: sintattica/atk
 /**
  * Delete the database in the session.
  *
  * @return bool Results, true or false
  */
 protected function _doDeleteSession()
 {
     $selector = Tools::atkArrayNvl($this->m_postvars, 'atkselector', '');
     return SessionStore::getInstance()->deleteDataRowForSelector($selector);
 }
コード例 #8
0
ファイル: FlagAttribute.php プロジェクト: sintattica/atk
 /**
  * Convert values from an HTML form posting to an internal value for
  * this attribute.
  *
  * For the regular Attribute, this means getting the field with the
  * same name as the attribute from the html posting.
  *
  * @param array $postvars The array with html posted values ($_POST, for
  *                        example) that holds this attribute's value.
  *
  * @return string The internal value
  */
 public function fetchValue($postvars)
 {
     $vars = Tools::atkArrayNvl($postvars, $this->fieldName());
     if (!is_array($vars)) {
         $result = [];
         foreach ($this->m_values as $value) {
             if (Tools::hasFlag($vars, $value)) {
                 $result[] = $value;
             }
         }
         return $result;
     } else {
         return $vars;
     }
 }
コード例 #9
0
ファイル: SecurityManager.php プロジェクト: sintattica/atk
 /**
  * Retrieve all known information about the currently logged-in user.
  *
  * @param $key string
  *
  * @return array Array with userinfo, or "" if no user is logged in.
  */
 public static function atkGetUser($key = '')
 {
     $sm = SessionManager::getInstance();
     $session = SessionManager::getSession();
     $user = '';
     $session_auth = is_object($sm) ? $sm->getValue('authentication', 'globals') : [];
     if (Config::getGlobal('authentication_session') && Tools::atkArrayNvl($session, 'login', 0) == 1 && $session_auth['authenticated'] == 1 && !empty($session_auth['user'])) {
         $user = $session_auth['user'];
         if (!isset($user['access_level']) || empty($user['access_level'])) {
             $user['access_level'] = 0;
         }
     }
     if ($key) {
         return $user[$key];
     }
     return $user;
 }
コード例 #10
0
ファイル: ViewEditBase.php プロジェクト: sintattica/atk
 /**
  * Get the current record from the database with the current selector.
  *
  * @return array
  */
 protected function getRecordFromSession()
 {
     $selector = Tools::atkArrayNvl($this->m_node->m_postvars, 'atkselector', '');
     return SessionStore::getInstance()->getDataRowForSelector($selector);
 }
コード例 #11
0
ファイル: DateAttribute.php プロジェクト: sintattica/atk
 /**
  * Returns a piece of html code that can be used in a form to edit this
  * attribute's value. (Month will be a dropdownbox, year and day text fields).
  *
  * @todo We can't show a calendar when we have a year dropdown?
  * @todo The calendar doesn't use the min/max values?
  *
  * @param array $record Array with 3 fields (year, month, day)
  * @param string $id html id
  * @param string $name html name
  * @param string $fieldprefix The fieldprefix
  * @param string $postfix
  * @param string $mode The mode ('add' or 'edit')
  * @param bool $obligatory Is this field obligatory or not
  *
  * @return string Piece a of HTML Code
  */
 public function draw($record = [], $id, $name, $fieldprefix = '', $postfix = '', $mode = '', $obligatory = false)
 {
     $result = '';
     // go in simplemode when a pda is detected
     if (BrowserInfo::detectPDA()) {
         $this->setSimpleMode(true);
     }
     $this->m_yeardropdown = false;
     if (!$this->m_simplemode) {
         self::registerScriptsAndStyles(!$this->hasFlag(self::AF_DATE_NO_CALENDAR));
     }
     $fieldname = $name . $postfix;
     /* text mode? */
     if ($this->hasFlag(self::AF_DATE_STRING) || $mode == 'list') {
         $value =& $record[$this->fieldName()];
         if (is_array($value)) {
             $value = adodb_date($this->m_date_format_edit, adodb_mktime(0, 0, 0, $value['month'], $value['day'], $value['year']));
         } elseif ($obligatory) {
             $value = adodb_date($this->m_date_format_edit);
         } else {
             $value = '';
         }
         $fieldname = $fieldname . '[date]';
         $result = '<input type="text" id="' . $id . '" class="atkdateattribute form-control" name="' . $fieldname . '" value="' . $value . '">';
         if (!$this->hasFlag(self::AF_DATE_NO_CALENDAR) && $mode != 'list') {
             $format = str_replace(array('y', 'Y', 'm', 'n', 'j', 'd'), array('yy', 'y', 'mm', 'm', 'd', 'dd'), $this->m_date_format_edit);
             $mondayFirst = 'false';
             if (is_bool(Tools::atktext('date_monday_first'))) {
                 $mondayFirst = Tools::atktext('date_monday_first') === true ? 'true' : $mondayFirst;
             }
             $result .= ' <input ' . $this->getCSSClassAttribute(['btn', 'btn-default', 'button', 'atkbutton', 'form-control']) . ' type="button" value="..." onclick="return showCalendar(\'' . $id . '\', \'' . $id . '\', \'' . $format . '\', false, ' . $mondayFirst . ');">';
         }
         return $result;
     }
     /* this field */
     $field = Tools::atkArrayNvl($record, $this->fieldName());
     $str_format = $this->m_date_format_edit;
     /* currently selected date */
     if (is_array($field) && $field['year'] == 0 && $field['month'] == 0 && $field['day'] == 0) {
         $current = null;
     } elseif (!is_array($field) && empty($field)) {
         $current = null;
     } elseif (is_array($field)) {
         if ($this->checkDateArray($field)) {
             $current = adodb_mktime(0, 0, 0, $field['month'], $field['day'], $field['year']);
         } else {
             $current = null;
             Tools::triggerError($record, $this->fieldName(), 'error_date_invalid');
         }
     } else {
         $date = self::dateArray($field);
         if ($this->checkDateArray($date)) {
             $current = adodb_mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
         } else {
             $current = null;
         }
     }
     /* minimum date */
     $minimum = $mode != 'search' ? $this->m_date_min : 0;
     if ($minimum != 0) {
         $str_min = adodb_date('Ymd', $minimum);
     } else {
         $str_min = 0;
     }
     /* maximum date */
     $maximum = $mode != 'search' ? $this->m_date_max : 0;
     if ($maximum != 0) {
         $str_max = adodb_date('Ymd', $maximum);
     } else {
         $str_max = 0;
     }
     $current = $this->getValidCurrentDate($current, $minimum, $maximum, $mode);
     /* get dates in array format */
     if ($current !== null) {
         $current = adodb_getdate($current);
     }
     if (!empty($minimum)) {
         $minimum = adodb_getdate($minimum);
     }
     if (!empty($maximum)) {
         $maximum = adodb_getdate($maximum);
     }
     /* minimum and maximum */
     $current['d_min'] = !empty($minimum) && $current['year'] == $minimum['year'] && $current['mon'] == $minimum['mon'] ? $minimum['mday'] : 1;
     $current['d_max'] = !empty($maximum) && $current['year'] == $maximum['year'] && $current['mon'] == $maximum['mon'] ? $maximum['mday'] : $this->getDays($current);
     $current['m_min'] = !empty($minimum) && $current['year'] == $minimum['year'] ? $minimum['mon'] : 1;
     $current['m_max'] = !empty($maximum) && $current['year'] == $maximum['year'] ? $maximum['mon'] : 12;
     $current['y_min'] = !empty($minimum) ? $minimum['year'] : 0;
     $current['y_max'] = !empty($maximum) ? $maximum['year'] : 0;
     /* small date selections, never possible is field isn't obligatory (no min/max date) */
     if (!empty($maximum) && !empty($minimum) && $str_max - $str_min < 25) {
         $str_script = '';
         if (count($this->m_onchangecode)) {
             $this->_renderChangeHandler($fieldprefix);
             $str_script = $this->getHtmlId($fieldprefix) . '_onChange(this);';
         }
         $result = '<select id="' . $id . '" name="' . $fieldname . '" onChange="' . $str_script . '" class="form-control select-standard">';
         for ($i = $str_min; $i <= $str_max; ++$i) {
             $tmp_date = adodb_getdate(adodb_mktime(0, 0, 0, substr($i, 4, 2), substr($i, 6, 2), substr($i, 0, 4)));
             $result .= '<option value="' . $i . '"' . ($current !== null && $tmp_date[0] == $current[0] ? ' selected' : '') . '>' . $this->formatDate($tmp_date, $str_format, !$this->hasFlag(self::AF_DATE_EDIT_NO_DAY)) . '</option>';
         }
         $result .= '</select>';
         return $result;
     }
     if ($this->hasFlag(self::AF_DATE_EMPTYFIELD)) {
         $emptyfield = true;
     } else {
         if (!$obligatory) {
             $emptyfield = true;
         } else {
             $emptyfield = false;
         }
     }
     $info = array('format' => $str_format, 'min' => $str_min, 'max' => $str_max, 'emptyfield' => $emptyfield, 'weekday' => !$this->hasFlag(self::AF_DATE_EDIT_NO_DAY));
     if (!$this->m_simplemode) {
         $result .= '<div class="' . $this->get_class_name() . ' form-inline"><script language="javascript">var atkdateattribute_' . $id . ' = ' . Json::encode($info) . ';</script>';
     }
     /* other date selections */
     $weekdayFormat = null;
     $str_script = '';
     for ($i = 0; $i < strlen($str_format); ++$i) {
         /* javascript method */
         if (!$this->m_simplemode) {
             $str_script = "AdjustDate(this, '" . $id . "');";
         }
         if (count($this->m_onchangecode)) {
             $this->_renderChangeHandler($fieldprefix);
             $str_script .= $this->getHtmlId($fieldprefix) . '_onChange(this);';
         }
         /* year input box */
         if ($str_format[$i] == 'y' || $str_format[$i] == 'Y') {
             $result .= $this->renderYear($id, $fieldname, $str_script, $current, $str_format[$i], $obligatory);
         } elseif ($str_format[$i] == 'D' || $str_format[$i] == 'l') {
             $weekdayFormat = $str_format[$i];
         } elseif ($str_format[$i] == 'j' || $str_format[$i] == 'd') {
             $result .= $this->renderDay($id, $fieldname, $str_script, $current, $str_format[$i], $obligatory, $weekdayFormat);
         } elseif ($str_format[$i] == 'm' || $str_format[$i] == 'n' || $str_format[$i] == 'M' || $str_format[$i] == 'F') {
             $result .= $this->renderMonth($id, $fieldname, $str_script, $current, $str_format[$i], $obligatory);
         } else {
             $result .= $str_format[$i];
         }
     }
     if (!$this->hasFlag(self::AF_DATE_NO_CALENDAR) && !$this->m_yeardropdown && !$this->m_simplemode && $mode != 'list') {
         $mondayFirst = 'false';
         if (is_bool(Tools::atktext('date_monday_first'))) {
             $mondayFirst = Tools::atktext('date_monday_first') === true ? 'true' : $mondayFirst;
         }
         $result .= ' <input ' . $this->getCSSClassAttribute(array('button', 'atkbutton', 'btn', 'btn-default', 'form-control')) . ' type="reset" value="..." onclick="return showCalendar(\'' . $id . '\', \'' . $id . '[year]\', \'y-mm-dd\', true, ' . $mondayFirst . ');">';
     }
     if (!$this->m_simplemode) {
         $result .= '</div>';
         // form-inline
     }
     return $result;
 }
コード例 #12
0
ファイル: NumberAttribute.php プロジェクト: sintattica/atk
 /**
  * Convert values from an HTML form posting to an internal value for
  * this attribute.
  *
  * If the user entered a number in his native language, he may have used
  * a different decimal separator, which we first convert to the '.'
  * standard separator (ATK uses the regular dot notation internally)
  *
  * @param array $postvars The array with html posted values ($_POST, for
  *                        example) that holds this attribute's value.
  *
  * @return string The internal value
  */
 public function fetchValue($postvars)
 {
     if ($this->isPosted($postvars)) {
         return $this->removeSeparators(Tools::atkArrayNvl($postvars, $this->fieldName(), ''));
     }
 }
コード例 #13
0
ファイル: UpdateHandler.php プロジェクト: sintattica/atk
 /**
  * Update a record in the session.
  *
  * @param array $record Record to update
  *
  * @return mixed Result of the update, true or false
  */
 private function updateRecordInSession($record)
 {
     $selector = Tools::atkArrayNvl($this->m_postvars, 'atkselector', '');
     return SessionStore::getInstance()->updateDataRowForSelector($selector, $record) !== false;
 }
コード例 #14
0
ファイル: Db.php プロジェクト: sintattica/atk
 /**
  * Get rows in an associative array with the given key column used as
  * key and the given value column used as value.
  *
  * NOTE:
  * This is not an efficient way to retrieve records, as this
  * will load all records into one array into memory. If you
  * retrieve a lot of records, you might hit the memory_limit
  * and your script will die.
  *
  * @param string $query query
  * @param int|string $keyColumn column index / name (default first column) to be used as key
  * @param int|string $valueColumn column index / name (default first column) to be used as value
  * @param int $offset offset
  * @param int $limit limit
  *
  * @return array rows
  */
 public function getValuesAssoc($query, $keyColumn = 0, $valueColumn = 1, $offset = -1, $limit = -1)
 {
     $rows = $this->getRowsAssoc($query, $keyColumn, $offset, $limit);
     foreach ($rows as $key => &$value) {
         if (is_numeric($valueColumn)) {
             $value = Tools::atkArrayNvl(array_values($value), $valueColumn);
         } else {
             $value = $value[$valueColumn];
         }
     }
     return $rows;
 }
コード例 #15
0
ファイル: TimeAttribute.php プロジェクト: sintattica/atk
 /**
  * Returns a piece of html code that can be used in a form to edit this
  * attribute's value.
  *
  * @param array $record The record that holds the value for this attribute.
  * @param string $fieldprefix The fieldprefix to put in front of the name
  *                            of any html form element for this attribute.
  * @param string $mode The mode we're in ('add' or 'edit')
  *
  * @return string A piece of htmlcode for editing this attribute
  */
 public function edit($record, $fieldprefix, $mode)
 {
     if ($this->m_default == "NOW" && $this->m_ownerInstance->m_action == "add" || $this->m_default == "" && $this->hasFlag(self::AF_OBLIGATORY) && !$this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
         $this->m_default = date("H:i:s");
     }
     $default = explode(":", $this->m_default);
     $id = $this->getHtmlId($fieldprefix);
     $name = $this->getHtmlName($fieldprefix);
     $field = Tools::atkArrayNvl($record, $this->fieldName());
     if ($field && !is_array($field)) {
         $field = self::parseTime($field);
     }
     $onChangeCode = '';
     if (count($this->m_onchangecode)) {
         $this->_renderChangeHandler($fieldprefix);
         $onChangeCode = ' onChange="' . $this->getHtmlId($fieldprefix) . '_onChange(this);"';
     }
     $m_hourBox = '<select id="' . $id . '[hours]" name="' . $name . "[hours]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
     $m_minBox = '<select id="' . $id . '[minutes]" name="' . $name . "[minutes]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
     $m_secBox = '<select id="' . $id . '[seconds]" name="' . $name . "[seconds]\" class=\"atktimeattribute form-control select-standard\"{$onChangeCode}>\n";
     if (is_array($field)) {
         $m_defHour = $field['hours'];
         $m_defMin = $field['minutes'];
         $m_defSec = $field['seconds'];
     } else {
         $m_defHour = $default[0];
         $m_defMin = $default[1];
         $m_defSec = $default[2];
     }
     Tools::atkdebug("defhour={$m_defHour}   defmin={$m_defMin}");
     // generate hour dropdown
     if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
         $m_hourBox .= '<option value=""' . ($m_defHour === '' ? ' selected' : '') . '></option>';
     }
     for ($i = $this->m_beginTime; $i <= $this->m_endTime; ++$i) {
         if ($m_defHour !== '' && $i == $m_defHour) {
             $sel = ' selected';
         } else {
             $sel = '';
         }
         $m_hourBox .= sprintf("<option value='%02d'%s>%02d</option>\n", $i, $sel, $i);
     }
     // generate minute dropdown
     if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
         $m_minBox .= '<option value=""' . ($m_defMin === '' ? ' selected' : '') . '></option>';
     }
     if ($this->hasFlag(self::AF_TIME_SECONDS)) {
         $minute_steps = range(00, 59);
     } else {
         $minute_steps = $this->m_steps;
     }
     for ($i = 0; $i <= count($minute_steps) - 1; ++$i) {
         if ($i != 0) {
             $prev = $minute_steps[$i - 1];
         } else {
             $prev = -1;
         }
         if ($minute_steps[$i] >= $m_defMin && $prev < $m_defMin && $m_defMin != '') {
             $sel = ' selected';
         } else {
             $sel = '';
         }
         $m_minBox .= sprintf("<option value='%02d'%s>%02d</option>\n", $minute_steps[$i], $sel, $minute_steps[$i]);
     }
     // generate second dropdown
     if (!$this->hasFlag(self::AF_OBLIGATORY) || $this->hasFlag(self::AF_TIME_DEFAULT_EMPTY)) {
         $m_secBox .= '<option value""' . ($m_defSec === '' ? ' selected' : '') . '></option>';
     }
     for ($i = 0; $i <= count($this->m_steps) - 1; ++$i) {
         if ($i != 0) {
             $prev = $this->m_steps[$i - 1];
         } else {
             $prev = -1;
         }
         if ($this->m_steps[$i] >= $m_defSec && $prev < $m_defSec && $m_defSec != '') {
             $sel = ' selected';
         } else {
             $sel = '';
         }
         $m_secBox .= sprintf("<option value='%02d' %s>%02d</option>\n", $this->m_steps[$i], $sel, $this->m_steps[$i]);
     }
     // close dropdown structures
     $m_hourBox .= '</select>';
     $m_minBox .= '</select>';
     if ($this->hasFlag(self::AF_TIME_SECONDS)) {
         $m_secBox .= '</select>';
         $m_secBox = ':' . $m_secBox;
     } else {
         $m_secBox = '<input type="hidden" id="' . $fieldprefix . $this->fieldName() . '[seconds]" name="' . $fieldprefix . $this->fieldName() . "[seconds]\" value=\"00\">\n";
     }
     // assemble display version
     $timeedit = $m_hourBox . ':' . $m_minBox . $m_secBox;
     return '<div class="' . $this->get_class_name() . ' form-inline">' . $timeedit . '</div>';
 }
コード例 #16
0
ファイル: ColumnConfig.php プロジェクト: sintattica/atk
 /**
  * Compare sortorder of two attributes.
  *
  * @param array $a
  * @param array $b
  *
  * @return int
  */
 public function _compareSortAttrs($a, $b)
 {
     return Tools::atkArrayNvl($a, 'sortorder', 0) <= Tools::atkArrayNvl($b, 'sortorder', 0) ? -1 : 1;
 }
コード例 #17
0
ファイル: CkAttribute.php プロジェクト: sintattica/atk
 public function display($record, $mode)
 {
     return Tools::atkArrayNvl($record, $this->fieldName(), '');
 }
コード例 #18
0
ファイル: Node.php プロジェクト: sintattica/atk
 /**
  * Determine the url for the feedbackpage.
  *
  * Output is dependent on the feedback configuration. If feedback is not
  * enabled for the action, this method returns an empty string, so the
  * result of this method can be passed directly to the redirect() method
  * after completing the action.
  *
  * The $record parameter is ignored by the default implementation, but
  * derived classes may override this method to perform record-specific
  * feedback.
  *
  * @param string $action The action that was performed
  * @param int $status The status of the action.
  * @param array $record The record on which the action was performed.
  * @param string $message An optional message to pass to the feedbackpage,
  *                          for example to explain the reason why an action
  *                          failed.
  * @param int $levelskip Number of levels to skip
  *
  * @return string The feedback url.
  */
 public function feedbackUrl($action, $status, $record = [], $message = '', $levelskip = null)
 {
     $sm = SessionManager::getInstance();
     $vars = [];
     $atkNodeUri = '';
     $sessionStatus = SessionManager::SESSION_BACK;
     if (isset($this->m_feedback[$action]) && Tools::hasFlag($this->m_feedback[$action], $status) || $status == ActionHandler::ACTION_FAILED) {
         $vars = array('atkaction' => 'feedback', 'atkfbaction' => $action, 'atkactionstatus' => $status, 'atkfbmessage' => $message);
         $atkNodeUri = $this->atkNodeUri();
         $sessionStatus = SessionManager::SESSION_REPLACE;
         // The level skip given is based on where we should end up after the
         // feedback action is shown to the user. This means that the feedback
         // action should be shown one level higher in the stack, hence the -1.
         // Default the feedback action is shown on the current level, so in that
         // case we have a simple SessionManager::SESSION_REPLACE with a level skip of null.
         $levelskip = $levelskip == null ? null : $levelskip - 1;
     }
     $dispatch_url = Tools::dispatch_url($atkNodeUri, Tools::atkArrayNvl($vars, 'atkaction', ''), $vars);
     return $sm->sessionUrl($dispatch_url, $sessionStatus, $levelskip);
 }
コード例 #19
0
ファイル: SessionManager.php プロジェクト: sintattica/atk
 /**
  * Retrieve a trace of the current session stack.
  *
  * @return array Array containing the title and url for each stacklevel.
  *               The url can be used to directly move back on the session
  *               stack.
  */
 public function stackTrace()
 {
     $sessionData =& self::getSession();
     $ui = Ui::getInstance();
     $res = [];
     $stack = $sessionData[$this->m_namespace]['stack'][$this->atkStackID()];
     for ($i = 0; $i < count($stack); ++$i) {
         if (!isset($stack[$i]['atknodeuri'])) {
             continue;
         }
         $node = $stack[$i]['atknodeuri'];
         $module = Tools::getNodeModule($node);
         $type = Tools::getNodeType($node);
         $action = $stack[$i]['atkaction'];
         $title = $ui->title($module, $type, $action);
         $descriptor = Tools::atkArrayNvl($stack[$i], 'descriptor', '');
         $entry = array('url' => '', 'title' => $title, 'descriptor' => $descriptor, 'node' => $node, 'nodetitle' => Tools::atktext($type, $module, $type), 'action' => $action, 'actiontitle' => Tools::atktext($action, $module, $type));
         if ($i < count($stack) - 1) {
             $entry['url'] = $this->sessionUrl(Config::getGlobal('dispatcher') . '?atklevel=' . $i);
         }
         $res[] = $entry;
     }
     return $res;
 }
コード例 #20
0
ファイル: IpAttribute.php プロジェクト: sintattica/atk
 /**
  * Converts a database value to an internal value.
  *
  * @param array $rec The database record that holds this attribute's value
  *
  * @return mixed The internal value
  */
 public function db2value($rec)
 {
     // By default, return the plain ip number
     if (!$this->hasFlag(self::AF_IP_STORENUMERIC)) {
         return Tools::atkArrayNvl($rec, $this->fieldName());
     }
     // But if the self::AF_IP_STORENUMERIC flag is set, we load it as long integer
     return IpUtils::ipStringFormat(Tools::atkArrayNvl($rec, $this->fieldName()));
 }
コード例 #21
0
ファイル: ExportHandler.php プロジェクト: sintattica/atk
 /**
  * the real import function
  * import the uploaded csv file for real.
  */
 public function doExport()
 {
     $enclosure = $this->m_postvars['enclosure'];
     $delimiter = $this->m_postvars['delimiter'];
     $source = $this->m_postvars;
     $list_includes = [];
     foreach ($source as $name => $value) {
         $pos = strpos($name, 'export_');
         if (is_integer($pos) and $pos == 0) {
             $list_includes[] = substr($name, strlen('export_'));
         }
     }
     $sm = SessionManager::getInstance();
     $sessionData =& SessionManager::getSession();
     $session_back = $sessionData['default']['stack'][$sm->atkStackID()][$sm->atkLevel() - 1];
     $atkorderby = $session_back['atkorderby'];
     $node = $this->m_node;
     $node_bk = $node;
     $num_atts = count($node_bk->m_attribList);
     $atts =& $node_bk->m_attribList;
     foreach ($atts as $name => $object) {
         $att = $node_bk->getAttribute($name);
         if (in_array($name, $list_includes) && $att->hasFlag(Attribute::AF_HIDE_LIST)) {
             $att->removeFlag(Attribute::AF_HIDE_LIST);
         } elseif (!in_array($name, $list_includes)) {
             $att->addFlag(Attribute::AF_HIDE_LIST);
         }
     }
     $rl = new CustomRecordList();
     $flags = ($node_bk->hasFlag(Node::NF_MRA) ? RecordList::RL_MRA : 0) | ($node_bk->hasFlag(Node::NF_MRPA) ? RecordList::RL_MRPA : 0);
     $node_bk->m_postvars = $session_back;
     if (isset($session_back['atkdg']['admin']['atksearch'])) {
         $node_bk->m_postvars['atksearch'] = $session_back['atkdg']['admin']['atksearch'];
     }
     if (isset($session_back['atkdg']['admin']['atksearchmode'])) {
         $node_bk->m_postvars['atksearchmode'] = $session_back['atkdg']['admin']['atksearchmode'];
     }
     $atkfilter = Tools::atkArrayNvl($source, 'atkfilter', '');
     $condition = $session_back['atkselector'] . ($session_back['atkselector'] != '' && $atkfilter != '' ? ' AND ' : '') . $atkfilter;
     $recordset = $node_bk->select($condition)->orderBy($atkorderby)->includes($list_includes)->mode('export')->getAllRows();
     if (method_exists($this->m_node, 'assignExportData')) {
         $this->m_node->assignExportData($list_includes, $recordset);
     }
     $recordset_new = [];
     foreach ($recordset as $row) {
         foreach ($row as $name => $value) {
             if (in_array($name, $list_includes)) {
                 $value = str_replace("\r\n", '\\n', $value);
                 $value = str_replace("\n", '\\n', $value);
                 $value = str_replace("\t", '\\t', $value);
                 $row[$name] = $value;
             }
         }
         $recordset_new[] = $row;
     }
     $filename = 'export_' . strtolower(str_replace(' ', '_', $this->getUi()->nodeTitle($node)));
     $rl->render($node_bk, $recordset_new, '', $enclosure, $enclosure, "\r\n", 1, '', '', array('filename' => $filename), 'csv', $source['generatetitlerow'], true, $delimiter);
     return true;
 }
コード例 #22
0
ファイル: ListAttribute.php プロジェクト: sintattica/atk
 /**
  * Returns a piece of html code that can be used in a form to edit this
  * attribute's value.
  *
  * @param array $record Array with fields
  * @param string $fieldprefix The fieldprefix to put in front of the name
  *                            of any html form element for this attribute.
  * @param string $mode The mode we're in ('add' or 'edit')
  *
  * @return string piece of html code with a checkbox
  */
 public function edit($record, $fieldprefix, $mode)
 {
     $id = $this->getHtmlId($fieldprefix);
     $name = $this->getHtmlName($fieldprefix);
     $hasNullOption = $this->hasNullOption();
     $selectOptions = [];
     $selectOptions['enable-select2'] = true;
     $selectOptions['dropdown-auto-width'] = true;
     $selectOptions['minimum-results-for-search'] = 10;
     $nullLabel = '';
     if ($hasNullOption) {
         $nullLabel = $this->getNullLabel();
         $selectOptions['with-empty-value'] = $this->getEmptyValue();
     }
     if (!empty($this->getWidth())) {
         $selectOptions['width'] = $this->getWidth();
     } else {
         $selectOptions['width'] = 'resolve';
     }
     $selectOptions = array_merge($selectOptions, $this->m_select2Options['edit']);
     $onchange = '';
     if (count($this->m_onchangecode)) {
         $onchange = ' onChange="' . $this->getHtmlId($fieldprefix) . '_onChange(this)"';
         $this->_renderChangeHandler($fieldprefix);
     }
     $data = '';
     foreach ($selectOptions as $k => $v) {
         $data .= ' data-' . $k . '="' . htmlspecialchars($v) . '"';
     }
     $result = '<select id="' . $id . '" name="' . $name . '" ' . $this->getCSSClassAttribute('form-control') . $onchange . $data . '>';
     if ($hasNullOption) {
         $result .= '<option value="' . $this->getEmptyValue() . '">' . $nullLabel . '</option>';
     }
     $values = $this->getValues();
     $recvalue = Tools::atkArrayNvl($record, $this->fieldName());
     for ($i = 0; $i < count($values); ++$i) {
         $sel = '';
         // If the current value is selected or occurs in the record
         if (!is_null($this->m_selected) && $values[$i] == $this->m_selected || is_null($this->m_selected) && $values[$i] == $recvalue && $recvalue !== '') {
             $sel = 'selected';
         }
         $result .= '<option value="' . $values[$i] . '" ' . $sel . '>' . $this->_translateValue($values[$i], $record);
     }
     $result .= '</select>';
     $result .= "<script>ATK.enableSelect2ForSelect('#{$id}');</script>";
     return $result;
 }
コード例 #23
0
ファイル: Zip.php プロジェクト: sintattica/atk
 /**
  * Get the error message based on the errorcode.
  *
  * @param int $type The type of zip (ATK_ZIP or ATK_UNZIP)
  * @param int $errorcode The errorcode
  *
  * @return string The errormessage
  */
 public function getInfozipError($type, $errorcode)
 {
     $codes = [];
     if ($type == self::ATKZIP_UNZIP) {
         $codes = array(0 => "Normal; no errors or warnings detected. (There may still be errors in the archive, but if so, they weren't particularly relevant to UnZip's processing and are presumably quite minor.)", 1 => 'One or more warning errors were encountered, but processing completed successfully anyway. This includes zipfiles where one or more files was skipped due to unsupported compression method or encryption with an unknown password.', 2 => 'A generic error in the zipfile format was detected. Processing may have completed successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.', 3 => 'A severe error in the zipfile format was detected. Processing probably failed immediately.', 4 => 'UnZip was unable to allocate memory for one or more buffers during program initialization.', 5 => 'UnZip was unable to allocate memory or unable to obtain a tty (terminal) to read the decryption password(s).', 6 => 'UnZip was unable to allocate memory during decompression to disk.', 7 => 'UnZip was unable to allocate memory during in-memory decompression.', 9 => 'The specified zipfile(s) was not found.', 10 => 'Invalid options were specified on the command line.', 11 => 'No matching files were found.', 50 => 'The disk is (or was) full during extraction.', 51 => 'The end of the ZIP archive was encountered prematurely.', 80 => 'The user aborted UnZip prematurely with control-C (or similar)', 81 => 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.', 82 => 'No files were found due to bad decryption password(s). (If even one file is successfully processed, however, the exit status is 1.)');
     } elseif ($type == self::ATKZIP_ZIP) {
         $codes = array(0 => 'Normal; no errors or warnings detected.', 2 => 'The zipfile is either truncated or damaged in some way (e.g., bogus internal offsets) that makes it appear to be truncated.', 3 => 'The structure of the zipfile is invalid; for example, it may have been corrupted by a text-mode ("ASCII") transfer.', 4 => 'Zip was unable to allocate sufficient memory to complete the command.', 5 => 'Internal logic error. (This should never happen; it indicates a programming error of some sort.)', 6 => 'ZipSplit was unable to create an archive of the specified size because the compressed size of a single included file is larger than the requested size. (Note that Zip and ZipSplit still do not support the creation of PKWARE-style multi-part archives.)', 7 => 'The format of a zipfile comment was invalid.', 8 => 'Testing (-T option) failed due to errors in the archive, insufficient memory to spawn UnZip, or inability to find UnZip.', 9 => 'Zip was interrupted by user (or superuser) action.', 10 => 'Zip encountered an error creating or using a temporary file.', 11 => 'Reading or seeking (jumping) within an input file failed.', 12 => 'There was nothing for Zip to do (e.g., "zip foo.zip").', 13 => 'The zipfile was missing or empty (typically when updating or freshening).', 14 => 'Zip encountered an error writing to an output file (typically the archive); for example, the disk may be full.', 15 => 'Zip could not open an output file (typically the archive) for writing.', 16 => 'The command-line parameters were specified incorrectly.', 18 => "Zip could not open a specified file for reading; either it doesn't exist or the user running Zip doesn't have permission to read it.");
     }
     return Tools::atkArrayNvl($codes, $errorcode, 'Unknown error code returned by Infozip');
 }
コード例 #24
0
ファイル: ManyToManyRelation.php プロジェクト: sintattica/atk
 /**
  * Returns a piece of html code for hiding this attribute in an HTML form,
  * while still posting its value. (<input type="hidden">).
  *
  * @param array $record
  * @param string $fieldprefix
  * @param string $mode
  *
  * @return string html
  */
 public function hide($record, $fieldprefix, $mode)
 {
     $result = '';
     if (is_array(Tools::atkArrayNvl($record, $this->fieldName())) && $this->createDestination()) {
         $ownerFields = $this->getOwnerFields();
         for ($i = 0, $_i = count($record[$this->fieldName()]); $i < $_i; ++$i) {
             if (Tools::atkArrayNvl($record[$this->fieldName()][$i], $this->getLocalKey())) {
                 $result .= '<input type="hidden" name="' . $this->getHtmlName($fieldprefix) . '[' . $i . '][' . $this->getLocalKey() . ']" value="' . $this->checkKeyDimension($record[$this->fieldName()][$i][$this->getLocalKey()], $ownerFields[0]) . '">';
             }
             if (Tools::atkArrayNvl($record[$this->fieldName()][$i], $this->getRemoteKey())) {
                 $result .= '<input type="hidden" name="' . $this->getHtmlName($fieldprefix) . '[' . $i . '][' . $this->getRemoteKey() . ']" value="' . $this->checkKeyDimension($record[$this->fieldName()][$i][$this->getRemoteKey()], $this->m_destInstance->primaryKeyField()) . '">';
             }
         }
     }
     return $result;
 }
コード例 #25
0
ファイル: Selector.php プロジェクト: sintattica/atk
 /**
  * Apply posted smart search criteria to query.
  *
  * @param Query $query query object
  */
 protected function _applyPostedSmartSearchCriteriaToQuery(Query $query)
 {
     $searchCriteria = Tools::atkArrayNvl($this->_getNode()->m_postvars, 'atksmartsearch');
     if (!is_array($searchCriteria) || count($searchCriteria) == 0) {
         return;
     }
     foreach ($searchCriteria as $id => $criterium) {
         $path = $criterium['attrs'];
         $value = $criterium['value'];
         $mode = $criterium['mode'];
         $attrName = array_shift($path);
         $attr = $this->_getNode()->getAttribute($attrName);
         if (is_object($attr)) {
             $attr->smartSearchCondition($id, 0, $path, $query, $this->_getNode()->getTable(), $value, $this->m_mode);
         }
     }
 }
コード例 #26
0
ファイル: IndexPage.php プロジェクト: sintattica/atk
 /**
  * Does the actual loading of the dispatch page
  * And adds it to the page for the dispatch() method to render.
  *
  * @param array $postvars The request variables for the node.
  * @param Node $node
  */
 public function loadDispatchPage($postvars, Node $node)
 {
     $node->m_postvars = $postvars;
     $node->m_action = $postvars['atkaction'];
     if (isset($postvars['atkpartial'])) {
         $node->m_partial = $postvars['atkpartial'];
     }
     $page = $node->getPage();
     $page->setTitle(Tools::atktext('app_shorttitle') . ' - ' . $node->getUi()->title($node->m_module, $node->m_type, $node->m_action));
     if ($node->allowed($node->m_action)) {
         $secMgr = SecurityManager::getInstance();
         $secMgr->logAction($node->m_type, $node->m_action);
         $node->callHandler($node->m_action);
         $id = '';
         if (isset($node->m_postvars['atkselector']) && is_array($node->m_postvars['atkselector'])) {
             $atkSelectorDecoded = [];
             foreach ($node->m_postvars['atkselector'] as $rowIndex => $selector) {
                 list($selector, $pk) = explode('=', $selector);
                 $atkSelectorDecoded[] = $pk;
                 $id = implode(',', $atkSelectorDecoded);
             }
         } else {
             list(, $id) = explode('=', Tools::atkArrayNvl($node->m_postvars, 'atkselector', '='));
         }
         $page->register_hiddenvars(array('atknodeuri' => $node->m_module . '.' . $node->m_type, 'atkselector' => str_replace("'", '', $id)));
     } else {
         $page->addContent($this->accessDeniedPage($node->getType()));
     }
 }