コード例 #1
0
function updateUser($db, $dbUser)
{
    $username = arrayExtract($dbUser, "username");
    $dbUser["table"] = "user";
    $where = array("username" => $username);
    return $db->update($dbUser, $where);
}
コード例 #2
0
function importUsers($users, $questions)
{
    $rows = array();
    foreach ($users as $user)
    {
        $username = arrayExtract($user, "username");
        if(!$username) continue;
        $username = str_replace(" ", "", $username);
        if(!$username) continue;

    //1 insert into user
        $userRow = array();
        $userRow["table"] = "user";
        $userRow["username"] = $username;
        $userRow["password"] = md5($username);
        $rows[] = $userRow;

    //2 insert into user_answer 1 row per user column
        foreach ($user as $column => $userValues)
        {
            if(!isset($questions[$column]) || !$userValues) continue;

            $q = $questions[$column];
//TODO: if question type == multiple,  $userValue is array: insert several rows
            $userValues = toArray($userValues, ";");
            foreach ($userValues as $key => $userValue)
            {
                $row = array();
                $row["table"] = "user_answer";
                $row["username"] = $username;
//              $row["field"] = $column;
//              $row["value"] = $userValue;
                $row["question_id"] = $q["id"];
                $answer = findAnswer($q, $userValue);
                if($answer)
                {
                    $row["answer_id"] = $answer["id"];
//                  $row["answer"] = $answer;

                    if(@$answer["value"])
                        $row["answer_value"] = $answer["value"];
                    else if(@$answer["data_type"] == "number")
                        $row["answer_value"] = $userValue;
                    else if(@$answer["data_type"] == "text")
                        $row["answer_text"] = $userValue;
                }
                else if(@$q["data_type"] == "number")
                    $row["answer_value"] = $userValue;
                else if(@$q["data_type"] == "text")
                    $row["answer_text"] = $userValue;

                if(@$row["answer_id"] || @$row["answer_text"] || @$row["answer_value"])
                    $rows[] = $row;
            }
        }
    }
    return $rows;
}
コード例 #3
0
 private function loadParentGroups()
 {
     if ($this->_parentGroups === false) {
         global $Controller;
         $this->_parentGroups = array();
         $groups = $Controller->get($this->_mygroupIds, OVERRIDE);
         $parentGroups = array();
         foreach ($groups as $g) {
             $parentGroups += $g->groups();
         }
         $this->_parentGroups = arrayExtract($parentGroups, 'ID');
     }
 }
コード例 #4
0
 function schematicEditor()
 {
     global $DB, $CONFIG, $USER, $Controller;
     $bookItems = $DB->booking_items->asArray(false, 'id,parent,place', false, false, 'place ASC');
     $Controller->get(arrayExtract($bookItems, 'id'));
     foreach ($bookItems as &$bi) {
         $bi['item'] = $Controller->{$bi['id']};
     }
     $inflatedBookItems = inflate($bookItems);
     $content = self::renderItems($inflatedBookItems);
     if ($this->mayI(EDIT)) {
         $content .= Form::quick(null, null, new Input(__('Object name'), 'oname'), new Select(__('Parent'), 'oparent', $inflatedBookItems, false, false, __('None')));
     }
     $this->setContent('main', $content);
 }
コード例 #5
0
function ageToYearBorn($db, &$params)
{
    $age = arrayExtract($params, "age");
    if (!$age) {
        return;
    }
    $age = explode(":", $age);
    $currentYear = date("Y");
    $years = array();
    foreach ($age as $a) {
        array_unshift($years, $a ? $currentYear - $a : $a);
    }
    $question = getFormQuestions($db, array("field_name" => "year_born"));
    if (!count($question)) {
        return;
    }
    debug("question", $question, true);
    $qid = $question[0]["id"];
    return $params["Q_{$qid}"] = implode(":", $years);
}
コード例 #6
0
 /**
  * Returns true if the given booking is one of the object's
  * @param $booking Booking
  * @return bool
  */
 function bookingExists($booking)
 {
     $this->loadBookingObject();
     $this->loadBookings(mktime(0, 0, 0, date('m', $booking['starttime']), date('d', $booking['starttime']), date('Y', $booking['starttime'])), mktime(0, 0, 0, date('m', $booking['starttime'] + $booking['duration']), date('d', $booking['starttime'] + $booking['duration']) + 1, date('Y', $booking['starttime'] + $booking['duration'])));
     if (in_array($booking['b_id'], arrayExtract($this->bookings, 'b_id'))) {
         return true;
     } else {
         return false;
     }
 }
コード例 #7
0
ファイル: index.php プロジェクト: esironal/exidoengine
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade ExidoEngine to newer
 * versions in the future. If you wish to customize ExidoEngine for your
 * needs please refer to http://www.exidoengine.com for more information.
 *
 * @license   http://www.exidoengine.com/license/gpl-3.0.html (GNU General Public License v3)
 * @author    ExidoTeam
 * @copyright Copyright (c) 2009 - 2013, ExidoEngine Solutions
 * @link      http://www.exidoengine.com/
 * @since     Version 1.0
 * @filesource
 *******************************************************************************/
// List actions menu
$view->action_menu = array('/user/action/create' => __('Create user'));
// Include menu code
$view->getView('layout/inc.list-action-menu-panel');
$helper->heading(__('Users'));
if ($view->item_list) {
    print tableOpen('-i-table -i-table-striped');
    print tableHead(array(__('ID'), __('User name'), __('Email'), __('Owner'), __('Group'), __('Role'), __('Joined at'), __('Status'), __('Actions')));
    foreach ($view->item_list as $item) {
        $item->is_enabled = htmlStatus($item->is_enabled);
        $item->created_at = dateConvertSQL2Human($item->created_at, Exido::config('global.date.format_long'));
        $item->actions = '<a href="user/action/edit/' . $item->user_id . '">' . __('Edit') . '</a> ';
        $item->actions .= '<a class="remove" href="user/action/remove/' . $item->user_id . '">' . __('Remove') . '</a>';
        print tableTR(arrayExtract((array) $item, array('user_id', 'user_name', 'user_email', 'owner_name', 'group_name', 'role_name', 'created_at', 'is_enabled', 'actions')));
    }
    print tableClose();
}
コード例 #8
0
 function editTab()
 {
     $_REQUEST->addType('view', 'string');
     $_REQUEST->addType('lang', 'string');
     $_REQUEST->setType('ch', 'numeric');
     global $Controller, $CONFIG, $DB, $USER;
     $this->setContent('header', __('Editing user') . ': ' . $this->that);
     $form = new Form('editUser');
     /**
      * User settings
      */
     global $SITE;
     $settingsform = $this->that->settings->getFormElements('usersettings');
     /**
      * Load voluntary groups
      * @var groups
      */
     $volkeys = $DB->{'spine,metadata'}->asList(array('spine.class' => 'Group', 'metadata.field' => 'GroupType', 'metadata.value' => array('vol', 'volpre')), 'spine.id');
     $volgroups = $Controller->get($volkeys, OVERRIDE);
     propsort($volgroups, 'Name');
     /**
      * Group membership page
      */
     $groups = $this->that->groups();
     $gTypes = array('vol' => array(), 'assigned' => array());
     foreach ($groups as $group) {
         if (!$group->isMember($this->that)) {
             continue;
         }
         switch ($group->GroupType) {
             case 'vol':
             case 'volpre':
                 $gTypes['vol'][] = $group->ID;
                 break;
             default:
                 $gTypes['assigned']['g' . $group->ID] = $group;
                 break;
         }
     }
     $checked = array();
     foreach ($volgroups as $vg) {
         if (in_array($vg->ID, $gTypes['vol'])) {
             $checked[] = $vg->ID;
         }
     }
     asort($gTypes['assigned']);
     return array(@$this->that->password !== 'LDAP' ? new Formsection(__('Login information'), new Input(__('Username'), 'username', @$this->that->username), new Password(__('Password'), 'password1'), new Password(__('Password again'), 'password2')) : null, new Formsection(__('Presentation'), new HTMLField(false, 'presentation', $this->that->getContent('presentation'))), $settingsform ? new Formsection(__('User settings'), $settingsform) : null, @UInfoFields::edit($id, 'Tab'), new Formsection(__('Group membership'), new Fieldset(__('Assigned groups'), listify(arrayExtract($gTypes['assigned'], 'link', false, true))), empty($volgroups) ? null : new checkset(__('Voluntary groups'), 'volgroups', $volgroups, $checked)));
 }
コード例 #9
0
ファイル: surveyFunc.php プロジェクト: ReadYun/vixik
function surveyInfoSelect($survey_code, $url)
{
    $survey['info'] = M(TB_BAS_SURVEY_INFO)->where("survey_code = '{$survey_code}'")->find();
    if ($survey['info']) {
        // $survey['info']['survey_desc'] = str_replace("\n", "<br/>", $survey['info']['survey_desc']) ;           // 调查说明输出前换行符转换
        $survey['url']['url_user'] = U('user/user/visit') . '?code=' . $survey['info']['user_code'];
        // 调查创建者访问地址
        $survey['url']['url_create'] = U('survey/survey/create') . '?code=' . $survey['info']['survey_code'];
        // 调查参与地址
        $survey['url']['url_visit'] = U('survey/survey/visit') . '?code=' . $survey['info']['survey_code'];
        // 调查参与地址
        $survey['url']['url_answer'] = U('survey/survey/answer') . '?code=' . $survey['info']['survey_code'];
        // 调查参与地址
        $survey['url']['url_analyse'] = U('survey/survey/analyse') . '?code=' . $survey['info']['survey_code'];
        // 调查分析地址
        $survey['stats']['answer_count'] = M(TB_BAS_SURVEY_ACTION)->where("survey_code = '{$survey_code}'")->count();
        // 参与统计
        $survey['stats']['follow_count'] = M(TB_BAS_USER_FOLLOW_SURVEY)->where("follow_code = '{$survey_code}'")->count();
        // 收藏统计
        $survey['stats']['share_count'] = M(TB_BAS_USER_SHARE_SURVEY)->where("share_code = '{$survey_code}'")->count();
        // 分享统计
        $option = optionInfoSelect($survey_code);
        $question = M(TB_BAS_QUESTION_INFO)->where("survey_code = '{$survey_code}'")->order('question_code')->select();
        // 自定义推荐规则查询
        if ($survey['info']['recomm_type'] == 2) {
            $survey['recommend'] = M(TB_BAS_SURVEY_RECOMMEND_RULE)->where("survey_code = '{$survey_code}'")->select();
        }
        for ($q = 0; $q < count($question); $q++) {
            $survey['question'][$q] = $question[$q];
            if ($question[$q]['question_type'] != 'textarea') {
                for ($o = 0, $i = 0; $o < count($option); $o++) {
                    if ($question[$q]['question_code'] == $option[$o]['question_code']) {
                        $survey['question'][$q]['option'][$i] = arrayExtract($option[$o], array('option_code', 'option_name', 'option_seq', 'option_type'));
                        $i++;
                    }
                }
            }
        }
        return $survey;
    } else {
        return false;
    }
}
コード例 #10
0
ファイル: apiFunc.php プロジェクト: ReadYun/vixik
function api_user_accout_update()
{
    $action = func_get_args()[0]['action'];
    // 取参数:用户行为
    $times_type = func_get_args()[0]['times_type'];
    // 取参数:次数类型
    $times_type = $_POST['times_type'];
    $action = json_decode($_POST['action'], true);
    // 用户行为信息
    $action['action_time'] = date('Y-m-d H:i:s');
    // 行为发生时间
    $user_code = $action['user_code'];
    $action_code = $action['action_code'];
    if ($times_type) {
        $times_type = $times_type . '_times';
    }
    // 取行为编码对应行为规则信息合并到用户行为信息数据中
    $actionConfig = M(TB_DET_USER_ACTION_CONFIG)->where("action_code = '{$action_code}'")->find();
    $action = array_merge($actionConfig, $action);
    // 生成行为名称$action['action_name']
    $condition = $action['action_column'] . '=' . $action['action_value'];
    $dtAction = M($action['action_table'])->where("{$condition}")->find();
    $target = $action['action_target'];
    $action['action_name'] = $dtAction[$target];
    // 取两个行为日志表表结构
    $keyBasScoreActionLog = M(TB_BAS_SCORE_ACTION_LOG)->getDbFields();
    $keyBasCoinsActionLog = M(TB_BAS_COINS_ACTION_LOG)->getDbFields();
    // 生成两个行为日志表对应字段的数据
    $action_score = arrayExtract($action, $keyBasScoreActionLog);
    $action_coins = arrayExtract($action, $keyBasCoinsActionLog);
    // 计算需要更新的用户积分值和金币值
    $accout_add['user_score'] = $action['score_value'] * $action['score_logic'];
    $accout_add['user_coins'] = $action['coins_value'] * $action['coins_logic'];
    if ($times_type) {
        $accout_add["{$times_type}"] = 1;
    }
    // 更新用户账户信息表中的金币积分等级
    if (userAccoutUpdate($user_code, $accout_add)) {
        if ($action_score['score_value']) {
            $res_sc = userActionAdd($action_score, 'score');
            // 用户积分累计日志
            // 如果更新过用户积分,再判断是否需要更新用户等级
            $userAccout = M(TB_BAS_USER_ACCOUT)->where("user_code = '{$user_code}'")->find();
            // 取当前用户账户信息
            $condition = "score_lower_value <= " . $userAccout['user_score'] . " and score_upper_value >= " . $userAccout['user_score'];
            $userLvl = M(TB_DET_USER_LEVEL)->where($condition)->find();
            // 取需要的积分规则
            // 如果计算出的最新等级与之前等级不同,更新用户最新等级
            if ($userLvl['user_level_value'] != $userAccout['user_level']) {
                $userAc['user_level'] = $userLvl['user_level_value'];
                alterUserAccout($user_code, $userAc);
            }
        }
        if ($action_coins['coins_value']) {
            $res_co = userActionAdd($action_coins, 'coins');
            // 用户金币使用日志
        }
    }
    if ($res_sc && $res_co) {
        $this->ajaxReturn(1, "success", 1);
    } else {
        $this->ajaxReturn(0, "failed", 0);
    }
}
コード例 #11
0
ファイル: SqlManager.php プロジェクト: araynaud/FoodPortrait
 private static function sqlWhere(&$params = null)
 {
     $sql = "";
     $sep = "WHERE";
     setIfNull($params, $_REQUEST);
     //TODO: list of reserved keywords. check if params are valid columm names
     unset($params["debug"]);
     unset($params["table"]);
     unset($params["group_by"]);
     unset($params["order_by"]);
     unset($params["limit"]);
     $where = arrayExtract($params, "where");
     foreach ($params as $key => $param) {
         $sql .= " {$sep} " . SqlManager::sqlCondition($params, $key, true);
         $sep = "AND";
     }
     if ($where) {
         $sql .= " {$sep} {$where}";
     }
     return $sql;
 }
コード例 #12
0
ファイル: query.php プロジェクト: araynaud/FoodPortrait
}
$username = fpCurrentUsername();
$db = new SqlManager($fpConfig);
if ($db->offline) {
    echo file_get_contents("query.json");
    return;
}
$questions = getFormQuestions($db);
$questions = arrayIndexBy($questions, "id");
//debugVar("questions", true);
$portraitType = arrayExtract($params, "portrait");
//convert age to year_born
ageToYearBorn($db, $params);
$order = arrayExtract($params, "order");
$groupBy = arrayExtract($params, "group");
$interval = arrayExtract($params, "interval");
if (!$groupBy) {
    $results = demographicPortrait($db, $params, $portraitType);
    //$users = arrayDistinct($results, "username");
    $users = filterUsers($db, $params);
    arrayDistinct($results, "username");
    setExists($results);
    $results = array("all" => $results);
} else {
    //if groupBy is a profile question, translate group=gender => group=Q_0
    $questionsByField = arrayIndexBy($questions, "field_name");
    if (array_key_exists($groupBy, $questionsByField)) {
        $qid = $questionsByField[$groupBy]["id"];
        $groupBy = "Q_{$qid}";
    }
    $groups = getDistinctGroups($db, $params, $groupBy, $interval);