Beispiel #1
0
 /**
  * 生成代码
  * @return void
  */
 public function run()
 {
     $className = strrev(substr(strstr(strrev(get_class($this)), '\\', true), 0, -2));
     Log::echoTrace('Generate ' . $className . ' Begin ...');
     $this->_exec();
     Log::echoTrace('Generate ' . $className . ' End');
 }
Beispiel #2
0
 /**
  * 刷新用户的所有分组
  * @param integer $userId
  * @param array $groupIds
  * @return array
  */
 public function modify($userId, array $groupIds)
 {
     if (($userId = (int) $userId) <= 0) {
         Log::warning(sprintf('Usergroups user_id "%d" must be greater than 0', $userId), 0, __METHOD__);
         return false;
     }
     $news = array();
     foreach ($groupIds as $value) {
         if (($value = (int) $value) > 0) {
             if (!in_array($value, $news)) {
                 $news[] = $value;
             }
         }
     }
     $olds = $this->findGroupIdsByUserId($userId);
     $groupIdCreates = array_diff($news, $olds);
     $groupIdRemoves = array_diff($olds, $news);
     $rowCountCreate = $this->getDb()->batchCreate($userId, $groupIdCreates);
     $rowCountRemove = $this->getDb()->batchRemove($userId, $groupIdRemoves);
     $totalCreate = count($groupIdCreates);
     $totalRemove = count($groupIdRemoves);
     $errorCreate = $totalCreate - $rowCountCreate;
     $errorRemove = $totalRemove - $rowCountRemove;
     if ($errorCreate > 0 || $errorRemove > 0) {
         Log::warning(sprintf('Usergroups user_id "%d", group_ids "%s", Create {total "%d", success "%d", error "%d"}, Remove {total "%d", success "%d", error "%d"}', $userId, serialize($groupIds), $totalCreate, $rowCountCreate, $errorCreate, $totalRemove, $rowCountRemove, $errorRemove), 0, __METHOD__);
         return false;
     }
     return true;
 }
Beispiel #3
0
 /**
  * 生成代码
  * @return void
  */
 public function run()
 {
     Log::echoTrace('Generate Begin, Table Name "' . $this->schema->tblName . '"');
     $GcDb = new GcDb($this->schema, $this->fileManager);
     $GcDb->run();
     $GcData = new GcData($this->schema, $this->fileManager);
     $GcData->run();
     $GcFormProcessor = new GcFormProcessor($this->schema, $this->fileManager);
     $GcFormProcessor->run();
     $GcService = new GcService($this->schema, $this->fileManager);
     $GcService->run();
     $GcSlang = new GcSlang($this->schema, $this->fileManager);
     $GcSlang->run();
     $GcLang = new GcLang($this->schema, $this->fileManager);
     $GcLang->run();
     $GcModel = new GcModel($this->schema, $this->fileManager);
     $GcModel->run();
     $GcController = new GcController($this->schema, $this->fileManager);
     $GcController->run();
     $GcActs = new GcActs($this->schema, $this->fileManager);
     $GcActs->run();
     $GcViews = new GcViews($this->schema, $this->fileManager);
     $GcViews->run();
     Log::echoTrace('Generate End, Table Name "' . $this->schema->tblName . '"');
 }
Beispiel #4
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['category_id']) || !isset($row['category_pid']) || !isset($row['category_name'])) {
             Log::warning(sprintf('FpCategories is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($params['category_name'])) {
             $newCategoryName = trim($params['category_name']);
             $oldCategoryName = $row['category_name'];
             if (isset($params['category_pid'])) {
                 $newCategoryPid = (int) $params['category_pid'];
                 $oldCategoryPid = (int) $row['category_pid'];
                 if ($newCategoryPid === $oldCategoryPid && $newCategoryName === $oldCategoryName) {
                     unset($params['category_pid'], $params['category_name']);
                 }
             } else {
                 if ($newCategoryName === $oldCategoryName) {
                     unset($params['category_name']);
                 }
             }
         }
     }
     $rules = array('category_name' => 'trim', 'category_pid' => 'intval', 'alias' => 'trim', 'meta_title' => 'trim', 'meta_keywords' => 'trim', 'meta_description' => 'trim', 'tpl_home' => 'trim', 'tpl_list' => 'trim', 'tpl_view' => 'trim', 'sort' => 'intval');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #5
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isInsert()) {
         if (!isset($params['m_rank_ids'])) {
             $params['m_rank_ids'] = array();
         }
         if (!is_array($params['m_rank_ids'])) {
             $params['m_rank_ids'] = (array) $params['m_rank_ids'];
         }
     } else {
         if (isset($params['m_rank_ids']) && !is_array($params['m_rank_ids'])) {
             $params['m_rank_ids'] = (array) $params['m_rank_ids'];
         }
         if (isset($params['poll_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['poll_key'])) {
                 Log::warning(sprintf('FpPolls is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $pollKey = trim($params['poll_key']);
             if ($pollKey === $row['poll_key']) {
                 unset($params['poll_key']);
             }
         }
     }
     $rules = array('poll_name' => 'trim', 'poll_key' => 'trim', 'allow_unregistered' => 'trim', 'join_type' => 'trim', 'interval' => 'intval', 'is_published' => 'trim', 'dt_publish_up' => 'trim', 'dt_publish_down' => 'trim', 'is_visible' => 'trim', 'is_multiple' => 'trim', 'max_choices' => 'intval', 'description' => 'trim', 'ext_info' => 'trim', 'dt_created' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #6
0
 /**
  * (non-PHPdoc)
  * @see \modules\builder\model\gc\AbstractGc::_exec()
  */
 protected function _exec()
 {
     Log::echoTrace('SRV Type "' . $this->schema->srvType . '" ...');
     if ($this->schema->srvType === 'normal') {
         $this->normal();
     }
     if ($this->schema->srvType === 'dynamic') {
         $this->dynamic();
     }
 }
Beispiel #7
0
 /**
  * 新增或编辑前执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onBeforeSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'advert\\services\\Adverts::create' ? true : false;
     $isModify = $context === 'advert\\services\\Adverts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     $enum = DataAdverts::getShowTypeEnum();
     $showType = isset($row['show_type']) ? trim($row['show_type']) : '';
     if (!isset($enum[$showType])) {
         return;
     }
     if ($showType === DataAdverts::SHOW_TYPE_CODE) {
         return;
     }
     if (isset($row['show_code'])) {
         unset($row['show_code']);
     }
     $columns = array('advert_url', 'title', 'advert_src', 'advert_src2', 'attr_alt', 'attr_width', 'attr_height', 'attr_fontsize', 'attr_target');
     $hasColumn = false;
     foreach ($row as $columnName => $value) {
         if (in_array($columnName, $columns)) {
             $hasColumn = true;
             break;
         }
     }
     if (!$hasColumn) {
         return;
     }
     if ($isModify) {
         if (($advertId = (int) $params) <= 0) {
             return;
         }
         $advert = Service::getInstance('Adverts', 'advert')->findByPk($advertId);
         if (!$advert || !is_array($advert) || !isset($advert['advert_id']) || !isset($advert['advert_url'])) {
             Log::warning(sprintf('PlgShowcode is unable to find the result by id "%d"', $advertId), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return;
         }
         foreach ($columns as $columnName) {
             if (!isset($row[$columnName])) {
                 $row[$columnName] = $advert[$columnName];
             }
         }
     }
     $typeKey = isset($row['type_key']) ? strtolower(trim($row['type_key'])) : '';
     if (in_array($typeKey, $this->_specialTypes)) {
         $object = Singleton::getInstance('advert\\plugins\\showcode\\Special' . ucfirst($typeKey));
     } else {
         $object = $this;
     }
     $object->setShowCode($showType, $row, $this);
 }
Beispiel #8
0
 /**
  * 发送邮件
  * @param string $toMail
  * @param string $subject
  * @param string $body
  * @return boolean
  */
 public static function sendMail($toMail, $subject, $body)
 {
     $smtp = null;
     if ($smtp === null) {
         $smtp = new Smtp(Options::getSmtpHost(), Options::getSmtpUsername(), Options::getSmtpPassword());
     }
     try {
         return $smtp->sendMail($toMail, $subject, $body);
     } catch (ErrorException $e) {
         Log::warning(sprintf('Tools sendMail Failed, SmtpHost: "%s", Message: "%s"', $smtp->getHost(), $e->getMessage()), $e->getCode(), __METHOD__);
     }
     return false;
 }
Beispiel #9
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         if (isset($params['type_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['type_key'])) {
                 Log::warning(sprintf('FpTypes is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $typeKey = trim($params['type_key']);
             if ($typeKey === $row['type_key']) {
                 unset($params['type_key']);
             }
         }
     }
     $rules = array('type_key' => 'trim', 'type_name' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #10
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         if (isset($params['topic_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['topic_key'])) {
                 Log::warning(sprintf('FpTopic is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $topicKey = trim($params['topic_key']);
             if ($topicKey === $row['topic_key']) {
                 unset($params['topic_key']);
             }
         }
     }
     $rules = array('topic_name' => 'trim', 'topic_key' => 'trim', 'cover' => 'trim', 'meta_title' => 'trim', 'meta_keywords' => 'trim', 'is_published' => 'trim', 'sort' => 'intval', 'use_header' => 'trim', 'use_footer' => 'trim', 'dt_created' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #11
0
 /**
  * 执行表单数据验证操作
  * @param string $opType
  * @param array $params
  * @param integer|array $id
  * @return boolean
  * @throws ErrorException 如果指定的操作类型不是INSERT或UPDATE,抛出异常
  * @throws ErrorException 如果是UPDATE操作类型但是ID小于等于0,抛出异常
  */
 public function run($opType, array $params, $id = 0)
 {
     $this->clearValues();
     $this->clearErrors();
     $this->_opType = strtoupper($opType);
     if (!defined('static::OP_' . $this->_opType)) {
         throw new ErrorException(sprintf('FormProcessor op type "%s" must be INSERT or UPDATE', $this->_opType));
     }
     $this->id = Clean::positiveInteger($id);
     if ($this->isUpdate() && $this->id === false) {
         $isArr = is_array($id);
         Log::warning(sprintf('FormProcessor op type is Update, "%s" "%s" must be greater than 0', $isArr ? 'IDs' : 'ID', $isArr ? serialize($id) : $id));
         return false;
     }
     $params = $this->_cleanPreProcess($params);
     if ($params === false) {
         return false;
     }
     if ($this->_process($params)) {
         return $this->_cleanPostProcess();
     }
     return false;
 }
Beispiel #12
0
 /**
  * (non-PHPdoc)
  * @see \tfc\db\Statement::getColumnCount()
  */
 public function getColumnCount()
 {
     try {
         return parent::getColumnCount();
     } catch (ErrorException $e) {
         Log::warning($e->getMessage(), $e->getCode(), __METHOD__);
     }
     return 0;
 }
Beispiel #13
0
 /**
  * 通过主键,删除一条记录
  * @param integer $memberId
  * @return integer
  */
 public function removeByPk($memberId)
 {
     if (($memberId = (int) $memberId) <= 0) {
         return false;
     }
     $portalTblName = $this->getTblprefix() . TableNames::getPortal();
     $membersTblName = $this->getTblprefix() . TableNames::getMembers();
     $socialTblName = $this->getTblprefix() . TableNames::getSocial();
     $sql = 'SELECT `p`.*, `m`.*, `s`.* FROM `' . $portalTblName . '` AS `p` LEFT JOIN `' . $membersTblName . '` AS `m` ON `p`.`member_id` = `m`.`member_id` LEFT JOIN `' . $socialTblName . '` AS `s` ON `m`.`member_id` = `s`.`member_id` WHERE `m`.`member_id` = ?';
     $row = $this->fetchAssoc($sql, $memberId);
     if (!$row || !is_array($row) || !isset($row['member_id'])) {
         return false;
     }
     Log::info(sprintf('Portal backup before remove: %s', serialize($row)), 0, __METHOD__);
     $commands = array(array('sql' => 'DELETE FROM `' . $portalTblName . '` WHERE `member_id` = ?', 'params' => $memberId), array('sql' => 'DELETE FROM `' . $membersTblName . '` WHERE `member_id` = ?', 'params' => $memberId), array('sql' => 'DELETE FROM `' . $socialTblName . '` WHERE `member_id` = ?', 'params' => $memberId));
     return $this->doTransaction($commands);
 }
Beispiel #14
0
 /**
  * 清理正整数数据,如果为负数则返回false
  * @param integer|array $value
  * @return mixed
  */
 public function cleanPositiveInteger($value)
 {
     $result = Clean::positiveInteger($value);
     if ($result === false) {
         $isArr = is_array($value);
         Log::warning(sprintf('AbstractService cleanPositiveInteger ARGS Error, "%s" "%s" must be greater than 0', $isArr ? 'PKs' : 'PK', $isArr ? serialize($value) : $value));
     }
     return $result;
 }
Beispiel #15
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPostProcess()
  */
 public function _cleanPostProcess()
 {
     if (isset($this->when)) {
         $enum = DataAddresses::getWhenEnum();
         if (!isset($enum[$this->when])) {
             $this->when = DataAddresses::WHEN_ANYONE;
         }
     }
     if (isset($this->is_default)) {
         $enum = DataAddresses::getIsDefaultEnum();
         if (!isset($enum[$this->is_default])) {
             $this->is_default = DataAddresses::IS_DEFAULT_N;
         }
     }
     if ($this->isUpdate()) {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['address_id']) || !isset($row['mobiphone']) || !isset($row['telephone'])) {
             Log::warning(sprintf('FpAddresses is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($this->mobiphone) && $this->mobiphone === '') {
             if (!isset($this->telephone) && $row['telephone'] === '') {
                 $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         if (isset($this->telephone) && $this->telephone === '') {
             if (!isset($this->mobiphone) && $row['mobiphone'] === '') {
                 $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         $consignee = isset($this->consignee) ? $this->consignee : $row['consignee'];
     }
     if (isset($this->mobiphone) && $this->mobiphone === '' && (isset($this->telephone) && $this->telephone === '')) {
         $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         return false;
     }
     if ($this->isInsert()) {
         $consignee = $this->consignee;
     }
     if ($this->isUpdate()) {
         if (!isset($this->addr_country_id) && !isset($this->addr_province_id) && !isset($this->addr_city_id) && !isset($this->addr_district_id)) {
             $this->address_name = $consignee . '-' . $row['addr_city'];
             return true;
         }
     }
     if (!isset($this->addr_country_id)) {
         $this->addr_country_id = 1;
     }
     if (!isset($this->addr_province_id)) {
         $this->addr_province_id = 0;
     }
     if (!isset($this->addr_city_id)) {
         $this->addr_city_id = 0;
     }
     if (!isset($this->addr_district_id)) {
         $this->addr_district_id = 0;
     }
     $addrCountryId = $this->addr_country_id;
     $addrProvinceId = $this->addr_province_id;
     $addrCityId = $this->addr_city_id;
     $addrDistrictId = $this->addr_district_id;
     $srv = Service::getInstance('Regions', 'system');
     $this->addr_country = $this->addr_province = $this->addr_city = $this->addr_district = '';
     $row = $srv->findByPk($addrCountryId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === 0 && (int) $row['region_type'] === 0) {
             $this->addr_country = $row['region_name'];
         }
     }
     if ($this->addr_country === '') {
         $this->addError('addr_country_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrProvinceId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCountryId && (int) $row['region_type'] === 1) {
             $this->addr_province = $row['region_name'];
         }
     }
     if ($this->addr_province === '') {
         $this->addError('addr_province_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrCityId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrProvinceId && (int) $row['region_type'] === 2) {
             $this->addr_city = $row['region_name'];
         }
     }
     if ($this->addr_city === '') {
         $this->addError('addr_city_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrDistrictId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCityId && (int) $row['region_type'] === 3) {
             $this->addr_district = $row['region_name'];
         }
     }
     if ($this->addr_district === '') {
         $this->addError('addr_district_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $this->address_name = $consignee . '-' . $this->addr_city;
     return true;
 }
Beispiel #16
0
 /**
  * 规范化输出数据的格式
  * 默认添加的输出内容:log_id (integer)
  *
  * 一.参数是字符串:
  * <pre>
  * $data = 'trotri';
  * 返回值:
  * $ret = array (
  *     'err_no' => 0,
  *     'err_msg' => '',
  *     'data' => 'trotri',
  *     'log_id' => 2000010
  * );
  * </pre>
  *
  * 二.参数是数组,但是没有指定err_no和err_msg:
  * <pre>
  * $data = array (
  *     'user_id' => 1,
  *     'user_name' => 'trotri'
  * );
  * 或
  * $data = array (
  *     'extra' => '', // 这个值将被丢弃
  *     'data' => array (
  *         'user_id' => 1,
  *         'user_name' => 'trotri'
  *     )
  * );
  * 返回值:
  * $ret = array (
  *     'err_no' => 0,
  *     'err_msg' => '',
  *     'data' => array (
  *         'user_id' => 1,
  *         'user_name' => 'trotri',
  *     ),
  *     'log_id' => 2000010
  * );
  * </pre>
  *
  * 三.参数是数组,并且已经指定err_no和err_msg:
  * <pre>
  * $data = array (
  *     'err_no' => 1001,
  *     'err_msg' => 'Login Failed',
  *     'user_id' => 1,
  *     'user_name' => 'trotri'
  * );
  * 或
  * $data = array (
  *     'err_no' => 1001,
  *     'err_msg' => 'Login Failed',
  *     'extra' => '', // 这个值将被丢弃
  *     'data' => array (
  *         'user_id' => 1,
  *         'user_name' => 'trotri'
  *     )
  * );
  * 返回值:
  * $ret = array (
  *     'err_no' => 1001,
  *     'err_msg' => 'Login Failed',
  *     'data' => array (
  *         'user_id' => 1,
  *         'user_name' => 'trotri'
  *     ),
  *     'log_id' => 2000010
  * );
  * </pre>
  * @param mixed $data
  * @return array
  */
 public function getViewData($data)
 {
     $errNo = ErrorNo::SUCCESS_NUM;
     $errMsg = '';
     if (is_array($data)) {
         if (isset($data['err_no'])) {
             $errNo = (int) $data['err_no'];
             unset($data['err_no']);
         }
         if (isset($data['err_msg'])) {
             $errMsg = $data['err_msg'];
             unset($data['err_msg']);
         }
         if (isset($data['data'])) {
             $data = $data['data'];
         }
     }
     $ret = array('err_no' => $errNo, 'err_msg' => $errMsg, 'data' => $data, 'log_id' => Log::getId());
     return $ret;
 }
Beispiel #17
0
 /**
  * 检查并上传文件
  * @param array $files
  * @return integer
  */
 public function save(array $files)
 {
     $errNo = self::SUCCESS_NUM;
     $upload = $this->getUpload();
     try {
         $upload->save($files);
     } catch (\Exception $e) {
         $errNo = $e->getCode();
         $errMsg = $e->getMessage();
         Log::warning($errMsg, $errNo, __METHOD__);
     }
     return $errNo;
 }
Beispiel #18
0
 /**
  * 初始化模板字段顺序
  * @return instance of modules\builder\model\gc\Schema
  */
 protected function _initViewColumns()
 {
     Log::echoTrace('Init View Columns Begin ...');
     $tmpListIndexShows = array();
     $tmpFormCreateShows = array();
     $tmpFormModifyShows = array();
     foreach ($this->fields as $rows) {
         if ($rows['index_show']) {
             $tmpListIndexShows[$rows['index_sort']][] = $rows['field_name'];
         }
         if ($rows['form_create_show']) {
             $tmpFormCreateShows[$rows['form_create_sort']][] = $rows['field_name'];
         }
         if ($rows['form_modify_show']) {
             $tmpFormModifyShows[$rows['form_modify_sort']][] = $rows['field_name'];
         }
     }
     ksort($tmpListIndexShows);
     ksort($tmpFormCreateShows);
     ksort($tmpFormModifyShows);
     $listIndexShows = array();
     $formViewShows = array();
     $formCreateShows = array();
     $formModifyShows = array();
     foreach ($tmpListIndexShows as $columnNames) {
         foreach ($columnNames as $columnName) {
             $listIndexShows[] = $columnName;
         }
     }
     foreach ($this->fields as $rows) {
         $formViewShows[] = $rows['field_name'];
     }
     foreach ($tmpFormCreateShows as $columnNames) {
         foreach ($columnNames as $columnName) {
             $formCreateShows[] = $columnName;
         }
     }
     foreach ($tmpFormModifyShows as $columnNames) {
         foreach ($columnNames as $columnName) {
             $formModifyShows[] = $columnName;
         }
     }
     $this->listIndexColumns = $listIndexShows;
     $this->formViewColumns = $formViewShows;
     $this->formCreateColumns = $formCreateShows;
     $this->formModifyColumns = $formModifyShows;
     Log::echoTrace('Init View Columns End');
 }
Beispiel #19
0
 /**
  * 通过表Metadata生成Builders数据
  * @param string $tblName
  * @return void
  */
 public function gb($tblName)
 {
     Ap::getResponse()->contentType();
     $tableNames = $this->_metadata->getTableNames($tblName);
     if (!in_array($tblName, $tableNames)) {
         Log::errExit(__LINE__, 'Table Name Not Exists!');
     }
     Log::echoTrace('Generate Begin, Table Name "' . $tblName . '"');
     $tableSchema = $this->_metadata->getTableSchema($tblName);
     $comments = $this->_metadata->getComments($tableSchema->name);
     $tblPrefix = $this->getDbProxy()->getTblprefix();
     $tblPreLen = strlen($tblPrefix);
     Log::echoTrace('Import to builders Begin ...');
     $params = array('builder_name' => isset($comments['__table__']) ? $comments['__table__'] : $tableSchema->name, 'tbl_name' => substr($tableSchema->name, $tblPreLen), 'tbl_profile' => DataBuilders::TBL_PROFILE_N, 'tbl_engine' => DataBuilders::TBL_ENGINE_INNODB, 'tbl_charset' => DataBuilders::TBL_CHARSET_UTF8, 'tbl_comment' => isset($comments['__table__']) ? $comments['__table__'] : '', 'srv_type' => DataBuilders::SRV_TYPE_NORMAL, 'srv_name' => 'undefined', 'app_name' => 'administrator', 'mod_name' => 'undefined', 'ctrl_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'cls_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'fk_column' => '', 'act_index_name' => 'index', 'act_view_name' => 'view', 'act_create_name' => 'create', 'act_modify_name' => 'modify', 'act_remove_name' => 'remove', 'index_row_btns' => array(DataBuilders::INDEX_ROW_BTNS_PENCIL, DataBuilders::INDEX_ROW_BTNS_REMOVE), 'description' => '', 'author_name' => UserIdentity::getNick(), 'author_mail' => UserIdentity::getName());
     $mod = Service::getInstance('Builders', $this->_srvName);
     $builderId = $mod->create($params);
     if ($builderId > 0) {
         Log::echoTrace('Import to builders Successfully ...');
     } else {
         $errors = $mod->getErrors();
         Log::errExit(__LINE__, 'Import to builders Failed! ' . serialize($errors));
     }
     Log::echoTrace('Import to builder_fields Begin ...');
     $sort = 0;
     foreach ($tableSchema->columns as $columnSchema) {
         $sort++;
         if ($columnSchema->type === 'integer') {
             $columnLength = $columnSchema->size;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $columnLength = str_replace(array('\'', ','), array('', '|'), substr(substr($columnSchema->dbType, 5), 0, -1));
         } elseif (stripos($columnSchema->dbType, 'char') !== false) {
             $columnLength = $columnSchema->size;
         } else {
             $columnLength = '';
         }
         if ($columnSchema->isPrimaryKey) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } else {
             $formRequired = DataFields::FORM_REQUIRED_Y;
         }
         if ($columnLength === 'y|n') {
             $typeId = 4;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $typeId = 5;
         } elseif ($columnSchema->isPrimaryKey) {
             $typeId = 9;
         } elseif ($columnSchema->type === 'integer') {
             $typeId = 2;
         } elseif (in_array($columnSchema->dbType, array('text', 'longtext'))) {
             $typeId = 10;
         } else {
             $typeId = 1;
         }
         $params = array('field_name' => $columnSchema->name, 'column_length' => $columnLength, 'column_auto_increment' => $columnSchema->isAutoIncrement ? DataFields::COLUMN_AUTO_INCREMENT_Y : DataFields::COLUMN_AUTO_INCREMENT_N, 'column_unsigned' => stripos($columnSchema->dbType, 'unsigned') !== false ? DataFields::COLUMN_UNSIGNED_Y : DataFields::COLUMN_UNSIGNED_N, 'column_comment' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : '', 'builder_id' => $builderId, 'group_id' => 1, 'type_id' => $typeId, 'sort' => $sort, 'html_label' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : $columnSchema->name, 'form_prompt' => '', 'form_required' => $formRequired, 'form_modifiable' => DataFields::FORM_MODIFIABLE_N, 'index_show' => DataFields::INDEX_SHOW_Y, 'index_sort' => $columnSchema->isPrimaryKey ? 1000 : $sort, 'form_create_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_CREATE_SHOW_N : DataFields::FORM_CREATE_SHOW_Y, 'form_create_sort' => $sort, 'form_modify_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_MODIFY_SHOW_N : DataFields::FORM_MODIFY_SHOW_Y, 'form_modify_sort' => $sort, 'form_search_show' => DataFields::FORM_SEARCH_SHOW_Y, 'form_search_sort' => $sort);
         $mod = Service::getInstance('Fields', $this->_srvName);
         $fieldId = $mod->create($params);
         if ($fieldId > 0) {
             Log::echoTrace('Import to builder_fields "' . $columnSchema->name . '" Successfully ...');
         } else {
             $errors = $mod->getErrors();
             Log::errExit(__LINE__, 'Import to builder_fields "' . $columnSchema->name . '" Failed! ' . serialize($errors));
         }
     }
     Log::echoTrace('Import to builder_fields Successfully ...');
     Log::echoTrace('Generate End, Table Name "' . $tblName . '"');
     exit;
 }
Beispiel #20
0
 /**
  * 调用从回收站还原数据类方法
  * @param \libsrv\AbstractService $object
  * @param string $method
  * @param integer|array $id
  * @return array
  */
 public function callRestoreMethod(AbstractService $object, $method, $id)
 {
     $rowCount = $object->{$method}($id);
     if ($rowCount === false) {
         $errNo = ErrorNo::ERROR_ARGS_RESTORE;
         $errMsg = Lang::_('ERROR_MSG_ERROR_DB_RESTORE');
         Log::warning(sprintf('%s callRestoreMethod, service "%s", method "%s", id "%s"', $errMsg, get_class($object), $method, is_array($id) ? serialize($id) : $id), $errNo, __METHOD__);
         return array('err_no' => $errNo, 'err_msg' => $errMsg, 'id' => $id);
     }
     $errNo = ErrorNo::SUCCESS_NUM;
     $errMsg = $rowCount > 0 ? Lang::_('ERROR_MSG_SUCCESS_RESTORE') : Lang::_('ERROR_MSG_ERROR_DB_AFFECTS_ZERO');
     Log::debug(sprintf('%s callRestoreMethod, service "%s", method "%s", id "%s", rowCount "%d"', $errMsg, get_class($object), $method, is_array($id) ? serialize($id) : $id, $rowCount), $errNo, __METHOD__);
     return array('err_no' => $errNo, 'err_msg' => $errMsg, 'id' => $id, 'row_count' => $rowCount);
 }
Beispiel #21
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if (isset($params['trash'])) {
         unset($params['trash']);
     }
     if (isset($params['category_name'])) {
         unset($params['category_name']);
     }
     if (isset($params['creator_name'])) {
         unset($params['creator_name']);
     }
     if (isset($params['last_modifier_name'])) {
         unset($params['last_modifier_name']);
     }
     if ($this->isInsert()) {
         if (isset($params['last_modifier_id'])) {
             unset($params['last_modifier_id']);
         }
         if (isset($params['last_modifier_name'])) {
             unset($params['last_modifier_name']);
         }
         $params['dt_created'] = $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_created'] = $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
         if (!isset($params['sort'])) {
             $params['sort'] = 10000;
         }
     } else {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['creator_id']) || !isset($row['allow_other_modify'])) {
             Log::warning(sprintf('FpPosts is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         $creatorId = isset($row['creator_id']) ? (int) $row['creator_id'] : 0;
         $lastModifierId = isset($params['last_modifier_id']) ? (int) $params['last_modifier_id'] : 0;
         if ($creatorId !== $lastModifierId) {
             if ($row['allow_other_modify'] !== DataPosts::ALLOW_OTHER_MODIFY_Y) {
                 $this->addError('allow_other_modify', Lang::_('SRV_FILTER_POSTS_ALLOW_OTHER_MODIFY_POWER'));
             }
         }
         if (isset($params['creator_id'])) {
             unset($params['creator_id']);
         }
         if (isset($params['creator_name'])) {
             unset($params['creator_name']);
         }
         if (isset($params['dt_created'])) {
             unset($params['dt_created']);
         }
         if (isset($params['ip_created'])) {
             unset($params['ip_created']);
         }
         if (isset($params['module_id'])) {
             unset($params['module_id']);
         }
         $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
     }
     $rules = array('title' => 'trim', 'alias' => 'trim', 'keywords' => 'trim', 'sort' => 'intval', 'category_id' => 'intval', 'module_id' => 'intval', 'password' => 'trim', 'picture' => 'trim', 'is_head' => 'trim', 'is_recommend' => 'trim', 'is_jump' => 'trim', 'jump_url' => 'trim', 'is_published' => 'trim', 'dt_publish_up' => 'trim', 'dt_publish_down' => 'trim', 'comment_status' => 'trim', 'allow_other_modify' => 'trim', 'hits' => 'intval', 'praise_count' => 'intval', 'comment_count' => 'intval', 'creator_id' => 'intval', 'last_modifier_id' => 'intval');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #22
0
 /**
  * 第三方账号登录
  * @param string $partner
  * @param string $openid
  * @return array
  */
 public function loginByPartner($partner, $openid)
 {
     if (($partner = trim($partner)) === '') {
         $errNo = DataAccount::ERROR_PARTNER_EMPTY;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     if (($openid = trim($openid)) === '') {
         $errNo = DataAccount::ERROR_OPENID_EMPTY;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     if (!in_array($partner, DataAccount::$partners)) {
         $errNo = DataAccount::ERROR_PARTNER_WRONG;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     $loginName = $partner . '_' . $openid;
     $row = $this->_portal->findByLoginName($loginName);
     if (!$row || !is_array($row) || !isset($row['member_id'])) {
         $salt = $this->_portal->getSalt();
         $password = $this->_portal->encrypt(String::randStr(12), $salt);
         $params = array('login_name' => $loginName, 'login_type' => DataPortal::LOGIN_TYPE_PARTNER, 'password' => $password, 'salt' => $salt, 'member_name' => mt_rand(100000000, 999999999), 'ip_registered' => Clean::ip2long(Ap::getRequest()->getClientIp()));
         if (!$this->_portal->getDb()->create($params)) {
             Log::warning(sprintf('Account db create failed, login_name "%s", login_type "%s"', $loginName, DataPortal::LOGIN_TYPE_PARTNER), 0, __METHOD__);
         }
     }
     $ret = $this->checkName($loginName);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     if ($ret['err_no'] !== DataAccount::SUCCESS_LOGIN_NUM) {
         return $ret;
     }
     $ret = $this->checkLogin($ret['data'], true);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     if ($ret['err_no'] !== DataAccount::SUCCESS_LOGIN_NUM) {
         return $ret;
     }
     $ret = $this->setIdentity($ret['data'], false);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     return $ret;
 }
Beispiel #23
0
 /**
  * 通过分析控制器文件,获取指定模块的控制器信息,并入库
  * @param integer $amcaId
  * @return void
  */
 public function synch($amcaId)
 {
     Log::echoTrace('Synch Begin ...');
     // 从数据库中读取模块数据
     Log::echoTrace('Query mod from table Begin ...');
     $ret = $this->findByPk($amcaId);
     if ($ret['err_no'] !== ErrorNo::SUCCESS_NUM) {
         Log::errExit(__LINE__, 'Query mod from table Failed!');
     }
     $mod = $ret['data'];
     if (!$this->isMod($mod['category'])) {
         Log::errExit(__LINE__, 'Amcas must be "' . DataAmcas::CATEGORY_MOD . '" category!');
     }
     Log::echoTrace('Query mod from table Successfully');
     // 从数据库中读取应用数据
     Log::echoTrace('Query app from table Begin ...');
     $ret = $this->findByPk($mod['amca_pid']);
     if ($ret['err_no'] !== ErrorNo::SUCCESS_NUM) {
         Log::errExit(__LINE__, 'Query app from table Failed!');
     }
     $app = $ret['data'];
     Log::echoTrace('Query app from table Successfully');
     $appName = $app['amca_name'];
     $modName = $mod['amca_name'];
     $modId = $mod['amca_id'];
     // 从数据库中读取控制器数据
     Log::echoTrace('Query ctrls from table Begin ...');
     $ret = $this->findAllByAmcaPid($modId);
     if ($ret['err_no'] !== ErrorNo::SUCCESS_NUM) {
         Log::errExit(__LINE__, 'Query ctrls from table Failed!');
     }
     $dbCtrls = array();
     foreach ($ret['data'] as $rows) {
         $dbCtrls[$rows['amca_name']] = $rows;
     }
     Log::echoTrace('Query ctrls from table Successfully');
     // 从文件中读取控制器数据
     Log::echoTrace('Query ctrls from files Begin ...');
     $fileManager = new FileManager();
     $directory = DIR_ROOT . DS . 'app' . DS . $appName . DS . 'modules' . DS . $modName . DS . 'controller';
     if (!$fileManager->isDir($directory)) {
         Log::errExit(__LINE__, sprintf('Ctrl Path "%s" is not a valid directory.', $directory));
     }
     $ctrls = array();
     $sort = 0;
     $filePaths = $fileManager->scanDir($directory);
     foreach ($filePaths as $filePath) {
         $ctrlName = basename($filePath, '.php');
         if ($ctrlName === 'index.html') {
             continue;
         }
         $clsName = 'modules\\' . $modName . '\\controller\\' . $ctrlName;
         require_once $filePath;
         $reflector = new \ReflectionClass($clsName);
         $amcaName = strtolower(substr($ctrlName, 0, -10));
         $prompt = preg_replace('/.+class\\s+file\\s+\\*\\s+(\\S+)\\s+\\*\\s+\\@author.+/is', '\\1', $reflector->getDocComment());
         $ctrls[$amcaName] = array('amca_pid' => $modId, 'amca_name' => $amcaName, 'prompt' => $prompt, 'sort' => $sort++, 'category' => DataAmcas::CATEGORY_CTRL);
     }
     Log::echoTrace('Query ctrls from files Successfully');
     Log::echoTrace('Analyser db and files Begin ...');
     $amcas = array('insert' => array(), 'update' => array(), 'delete' => array());
     foreach ($ctrls as $amcaName => $rows) {
         if (isset($dbCtrls[$amcaName])) {
             if ($dbCtrls[$amcaName]['prompt'] != $rows['prompt'] || $dbCtrls[$amcaName]['sort'] != $rows['sort']) {
                 $amcas['update'][$dbCtrls[$amcaName]['amca_id']] = $rows;
             }
         } else {
             $amcas['insert'][] = $rows;
         }
     }
     foreach ($dbCtrls as $amcaName => $rows) {
         if (!isset($ctrls[$amcaName])) {
             $amcas['delete'][] = $rows['amca_id'];
         }
     }
     Log::echoTrace('Analyser db and files Successfully');
     $dbAmcas = new DbAmcas();
     Log::echoTrace('Import to db Begin ...');
     foreach ($amcas['insert'] as $attributes) {
         $ret = $dbAmcas->create($attributes);
         if (!$ret) {
             Log::errExit(__LINE__, sprintf('Insert to table "%s" Failed!', $attributes['amca_name']));
         }
         Log::echoTrace(sprintf('Insert into table "%s" Successfully', $attributes['amca_name']));
     }
     foreach ($amcas['update'] as $amcaId => $attributes) {
         $ret = $dbAmcas->modifyByPk($amcaId, $attributes);
         if (!$ret) {
             Log::errExit(__LINE__, sprintf('Update table "%s" Failed!', $attributes['amca_name']));
         }
         Log::echoTrace(sprintf('Update table "%s" Successfully', $attributes['amca_name']));
     }
     foreach ($amcas['delete'] as $amcaId) {
         $ret = $dbAmcas->removeByPk($amcaId);
         if (!$ret) {
             Log::errExit(__LINE__, sprintf('Delete from table "%d" Failed!', $amcaId));
         }
         Log::echoTrace(sprintf('Delete from "%d" Successfully', $amcaId));
     }
     Log::echoTrace('Import to db Successfully');
     Log::echoTrace('Synch Successfully');
 }
Beispiel #24
0
 /**
  * 从Cookie中获取用户身份信息并设置到用户身份管理类
  * @return boolean
  */
 public function initIdentity()
 {
     $clusterName = self::CLUSTER_NAME;
     $config = Cfg::getApp($clusterName);
     $expiry = isset($config['expiry']) ? (int) $config['expiry'] : 0;
     $cookieName = isset($config['cookie_name']) ? trim($config['cookie_name']) : '';
     $cooksetPassword = isset($config['cookset_password']) ? (bool) $config['cookset_password'] : false;
     $cooksetRoleNames = isset($config['cookset_rolenames']) ? (bool) $config['cookset_rolenames'] : false;
     $cooksetAppNames = isset($config['cookset_appnames']) ? (bool) $config['cookset_appnames'] : false;
     if ($cookieName === '') {
         Log::warning(sprintf('Account cookie name must be string and not empty, cluster_name "%s"', $clusterName), 0, __METHOD__);
         return false;
     }
     $authentica = new Authentica($clusterName);
     $data = $authentica->getIdentity();
     if (!$data || !is_array($data) || !isset($data['user_id'])) {
         Log::debug(sprintf('Account cookie data must be array and not empty, cluster_name "%s", cookie_name "%s"', $clusterName, $cookieName), 0, __METHOD__);
         return false;
     }
     $userId = isset($data['user_id']) ? (int) $data['user_id'] : 0;
     $loginName = isset($data['user_name']) ? trim($data['user_name']) : '';
     $password = isset($data['password']) ? $data['password'] : '';
     $ip = isset($data['ip']) ? (int) $data['ip'] : 0;
     $expiry = isset($data['expiry']) ? (int) $data['expiry'] : 0;
     $time = isset($data['time']) ? (int) $data['time'] : 0;
     $nickname = isset($data['nickname']) ? trim($data['nickname']) : '';
     $roleNames = isset($data['role_names']) ? (array) $data['role_names'] : array();
     $extends = isset($data['extends']) ? $data['extends'] : '';
     if ($userId <= 0 || $loginName === '') {
         Log::warning(sprintf('Account cookie user_id and login_name must be not empty, cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
         return false;
     }
     $clientIp = ip2long(Ap::getRequest()->getClientIp());
     if ($ip !== $clientIp) {
         Log::warning(sprintf('Account cookie ip "%s" is not equal to client ip "%s", cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', long2ip($ip), long2ip($clientIp), $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
         return false;
     }
     if ($cooksetPassword) {
         if ($password === '') {
             Log::warning(sprintf('Account config cookset_password and cookie password must be not empty, cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
             return false;
         }
         $dbpwd = $this->_users->getPasswordByUserId($userId);
         if ($password !== $dbpwd) {
             Log::warning(sprintf('Account cookie password "%s" is not equal to db password "%s", cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
             return false;
         }
     }
     $groupIds = $roleNames;
     $appNames = explode(',', $extends);
     $authoriz = $this->getAuthoriz($roleNames);
     Identity::setAll($userId, $loginName, $nickname, $roleNames, $appNames, 0, 0, $authoriz);
     return true;
 }
Beispiel #25
0
 /**
  * 通过主键,编辑“权限设置”
  * <pre>
  * $params = array (
  *   'app_name' => array (
  *     'mod_name' => array (
  *       'ctrl_name' => array (
  *         'Power-SELECT', 'Power-INSERT', 'Power-UPDATE', 'Power-DELETE'
  *       )
  *     )
  *   )
  * );
  * 示例:
  * $params = array (
  *   'administrator' => array (
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'posts' => array (
  *       'categories' => array ( '1', '2', '4', '8' ),
  *       'modules' => array ( '1', '2', '4', '8' ),
  *       'posts' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'passport' => array (
  *     'system' => array (
  *       'options' => array ( '1', '2', '4', '8' ),
  *       'pictures' => array ( '1', '2', '4', '8' ),
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'users' => array (
  *       'account' => array ( '1', '2', '4', '8' ),
  *       'amcas' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'users' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'programmer' => array (
  *     'builder' => array (
  *       'builders' => array ( '1', '2', '4', '8' ),
  *       'fields' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'tblnames' => array ( '1', '2', '4', '8' ),
  *       'types' => array ( '1', '2', '4', '8' ),
  *       'validators' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  * );
  * </pre>
  * @param integer $groupId
  * @param array $params
  * @return array
  */
 public function modifyPermissionByPk($groupId, array $params)
 {
     if (($groupId = (int) $groupId) <= 0) {
         Log::warning(sprintf('Groups group_id "%d" must be greater than 0', $groupId), 0, __METHOD__);
         return false;
     }
     $amcas = Service::getInstance('Amcas', $this->_srvName)->findAllByRecur();
     $powerEnum = DataGroups::getPowerEnum();
     $data = array();
     foreach ($params as $appName => $mods) {
         if (!isset($amcas[$appName])) {
             Log::warning(sprintf('Groups is unable to find the app name "%s".', $appName), 0, __METHOD__);
             return false;
         }
         if (!is_array($mods)) {
             continue;
         }
         foreach ($mods as $modName => $ctrls) {
             if (!isset($amcas[$appName]['rows'][$modName])) {
                 Log::warning(sprintf('Groups is unable to find the mod name "%s-%s".', $appName, $modName), 0, __METHOD__);
                 return false;
             }
             if (!is_array($ctrls)) {
                 continue;
             }
             foreach ($ctrls as $ctrlName => $powers) {
                 if (!isset($amcas[$appName]['rows'][$modName]['rows'][$ctrlName])) {
                     Log::warning(sprintf('Groups is unable to find the ctrl name "%s-%s-%s".', $appName, $modName, $ctrlName), 0, __METHOD__);
                     return false;
                 }
                 if (!is_array($powers)) {
                     continue;
                 }
                 foreach ($powers as $power) {
                     $power = (int) $power;
                     if (!isset($powerEnum[$power])) {
                         Log::warning(sprintf('Groups is unable to find the power "%s-%s-%s-%d".', $appName, $modName, $ctrlName, $power), 0, __METHOD__);
                         return false;
                     }
                     $data[$appName][$modName][$ctrlName][] = $power;
                 }
             }
         }
     }
     $data = base64_encode(serialize($data));
     $rowCount = $this->getDb()->modifyPermissionByPk($groupId, $data);
     if ($rowCount > 0) {
         $authoriz = new Authoriz();
         if (!$authoriz->flush()) {
             Log::warning('Groups Authoriz flush roles cache Failed.', 0, __METHOD__);
         }
     }
     return $rowCount;
 }
Beispiel #26
0
 /**
  * CURL方式提交数据
  * @param string $pathinfo
  * @param array $params
  * @param string $method
  * @return mixed
  */
 public function talk($pathinfo, array $params = array(), $method = 'GET')
 {
     $ral = $this->getRal();
     $ral->setLogId(Log::getId());
     $maxRetry = $this->getRetry();
     for ($retry = 0; $retry < $maxRetry; $retry++) {
         try {
             $result = $ral->talk($pathinfo);
             $message = 'Ral Exec Curl Successfully!';
             $code = 0;
         } catch (ErrorException $e) {
             $message = 'Ral Exec Curl Failed! ' . $e->getMessage();
             $code = $e->getCode();
             $result = false;
         }
         $event = array('msg' => $message, 'retry' => $retry, 'pathinfo' => $pathinfo, 'params' => serialize($params), 'method' => $method, 'config' => serialize($this->getConfig()));
         if ($result !== false) {
             Log::notice($event, __METHOD__);
             return $result;
         }
         Log::warning($event, $code, __METHOD__);
     }
     return $result;
 }
Beispiel #27
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if (isset($params['trash'])) {
         unset($params['trash']);
     }
     if ($this->isInsert()) {
         if (isset($params['salt'])) {
             unset($params['salt']);
         }
         if (isset($params['relation_member_id'])) {
             unset($params['relation_member_id']);
         }
         if (isset($params['dt_last_repwd'])) {
             unset($params['dt_last_repwd']);
         }
         if (isset($params['ip_last_repwd'])) {
             unset($params['ip_last_repwd']);
         }
         if (isset($params['repwd_count'])) {
             unset($params['repwd_count']);
         }
         $params['dt_registered'] = $params['dt_last_login'] = date('Y-m-d H:i:s');
         $params['ip_registered'] = $params['ip_last_login'] = Clean::ip2long(Ap::getRequest()->getClientIp());
         $params['login_count'] = 1;
         $params['salt'] = $this->_object->getSalt();
         $params['login_name'] = $loginName = isset($params['login_name']) ? trim($params['login_name']) : '';
         $params['login_type'] = $loginType = $this->_object->getLoginType($loginName);
         if ($this->_object->isMailLogin($loginType)) {
             if (!isset($params['member_mail']) || trim($params['member_mail']) === '') {
                 $params['member_mail'] = $loginName;
             }
         } elseif ($this->_object->isPhoneLogin($loginType)) {
             if (!isset($params['member_phone']) || trim($params['member_phone']) === '') {
                 $params['member_phone'] = $loginName;
             }
         }
         if (!isset($params['member_name']) || trim($params['member_name']) === '') {
             if ($this->_object->isMailLogin($loginType)) {
                 $params['member_name'] = strstr($loginName, '@', true);
             } else {
                 $params['member_name'] = $loginName;
             }
         }
     } else {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['repwd_count'])) {
             Log::warning(sprintf('FpPortal is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($params['login_name'])) {
             unset($params['login_name']);
         }
         if (isset($params['login_type'])) {
             unset($params['login_type']);
         }
         if (isset($params['salt'])) {
             unset($params['salt']);
         }
         if (isset($params['dt_registered'])) {
             unset($params['dt_registered']);
         }
         if (isset($params['ip_registered'])) {
             unset($params['ip_registered']);
         }
         $password = isset($params['password']) ? trim($params['password']) : '';
         if ($password !== '') {
             if (!isset($params['repassword'])) {
                 $params['repassword'] = '';
             }
             $params['salt'] = $this->_object->getSalt();
             $params['dt_last_repwd'] = date('Y-m-d H:i:s');
             $params['ip_last_repwd'] = Clean::ip2long(Ap::getRequest()->getClientIp());
             $params['repwd_count'] = (int) $row['repwd_count'] + 1;
         } else {
             if (isset($params['password'])) {
                 unset($params['password']);
             }
             if (isset($params['repassword'])) {
                 unset($params['repassword']);
             }
             if (isset($params['dt_last_repwd'])) {
                 unset($params['dt_last_repwd']);
             }
             if (isset($params['ip_last_repwd'])) {
                 unset($params['ip_last_repwd']);
             }
             if (isset($params['repwd_count'])) {
                 unset($params['repwd_count']);
             }
         }
     }
     $rules = array('login_name' => 'trim', 'login_type' => 'trim', 'password' => 'trim', 'repassword' => 'trim', 'salt' => 'trim', 'member_name' => 'trim', 'member_mail' => 'trim', 'member_phone' => 'trim', 'relation_member_id' => 'intval', 'dt_registered' => 'trim', 'dt_last_login' => 'trim', 'dt_last_repwd' => 'trim', 'ip_registered' => 'intval', 'ip_last_login' => 'intval', 'ip_last_repwd' => 'intval', 'login_count' => 'intval', 'repwd_count' => 'intval', 'valid_mail' => 'trim', 'valid_phone' => 'trim', 'forbidden' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #28
0
 /**
  * 批量编辑排序
  * @param array $params
  * @return integer
  */
 public function batchModifySort(array $params = array())
 {
     $rowCount = 0;
     $columnName = 'sort';
     foreach ($params as $pk => $value) {
         if ($this->batchModifyByPk($pk, array($columnName => $value))) {
             $rowCount += 1;
         } else {
             $errors = $this->getErrors();
             if ($errors) {
                 Log::warning(sprintf('Posts update args error, id "%d", params "%s", errors "%s"', $pk, serialize($params), serialize($errors)), 0, __METHOD__);
             }
         }
     }
     return $rowCount;
 }
Beispiel #29
0
 /**
  * 创建 Trash Action
  * @return void
  */
 public function actTrash()
 {
     $fileManager = $this->fileManager;
     $schema = $this->schema;
     $clsName = ucfirst($schema->actTrashName);
     $filePath = $fileManager->action . DS . $clsName . '.php';
     $stream = $fileManager->fopen($filePath);
     $fileManager->writeCopyrightComment($stream);
     fwrite($stream, "namespace modules\\{$schema->modName}\\action\\{$schema->ctrlName};\n\n");
     fwrite($stream, "use library\\actions;\n\n");
     $fileManager->writeClassComment($stream, $clsName, '移至回收站和从回收站还原', "modules.{$schema->modName}.action.{$schema->ctrlName}");
     fwrite($stream, "class {$clsName} extends actions\\Trash\n");
     fwrite($stream, "{\n");
     fwrite($stream, "\t/**\n");
     fwrite($stream, "\t * (non-PHPdoc)\n");
     fwrite($stream, "\t * @see \\tfc\\mvc\\interfaces\\Action::run()\n");
     fwrite($stream, "\t */\n");
     fwrite($stream, "\tpublic function run()\n");
     fwrite($stream, "\t{\n");
     fwrite($stream, "\t\t\$this->execute('{$schema->ucClsName}');\n");
     fwrite($stream, "\t}\n");
     fwrite($stream, "}\n");
     fclose($stream);
     Log::echoTrace('Generate App Act ' . $clsName . ' Successfully');
 }
Beispiel #30
0
 /**
  * 创建 TrashIndex Btns View
  * @return void
  */
 public function viwTrashIndexBtns()
 {
     $fileManager = $this->fileManager;
     $schema = $this->schema;
     $tmpFileName = $schema->ctrlName . '_' . strtolower($schema->actTrashIndexName) . '_btns';
     $filePath = $fileManager->view . DS . $tmpFileName . '.php';
     $stream = $fileManager->fopen($filePath);
     fclose($stream);
     Log::echoTrace('Generate App View ' . $tmpFileName . ' Successfully');
 }