Пример #1
0
/**
 * 任务表单字段的验证
 *
 * @author yumin
 * @param $data 表单提交数组
 * @return $task 结果以及错误
 */
function validator_submit_task($data)
{
    global $action;
    // 综合验证
    if (empty($data)) {
        $task['error']['all'] = '服务器只是个传说,啥都没填写的话,就别提交了嘛!';
        return $task;
    }
    // 负责人
    $key = 'owner_id';
    if (isset($data[$key]) && 0 < $data[$key]) {
        if ('add' == $action) {
            $task['ret']['owners'] = !is_array($data[$key]) ? array($data[$key]) : $data[$key];
        } elseif ('update' == $action) {
            $task['ret']['owner_id'] = $data[$key];
        }
    } else {
        $task['error'][$key] = '负责人是必选项';
    }
    //print_r($task['ret']['owner_id']);exit;
    // 所属项目
    $key = 'pid';
    if (isset($data[$key]) && 0 < $data[$key]) {
        $task['ret'][$key] = $data[$key];
    } else {
        $task['ret'][$key] = 0;
    }
    // 任务名称
    $key = 'taskname';
    if (isset($data[$key]) && !empty($data[$key])) {
        $task['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $task['error'][$key] = '任务名称是必填项';
    }
    // owner
    $key = 'owner';
    if (isset($data[$key]) && !empty($data[$key])) {
        $task['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $task['ret'][$key] = '';
    }
    // 优先级
    $key = 'priority';
    if (isset($data[$key]) && 0 <= $data[$key]) {
        $task['ret'][$key] = $data[$key];
    } else {
        $task['error'][$key] = '优先级是必选项';
    }
    // 计划起始时间
    $key = 'plan_start_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $start = strtotime($data[$key]);
        if (0 < $start) {
            $task['ret'][$key] = $start;
        } else {
            $task['ret'][$key] = 0;
        }
    } else {
        $task['ret'][$key] = 0;
    }
    // 计划截止时间
    $key = 'plan_end_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $end = strtotime($data[$key]);
        if (0 < $end) {
            $task['ret'][$key] = $end;
        } else {
            $task['ret'][$key] = 0;
        }
    } else {
        $task['ret'][$key] = 0;
    }
    // 实际开始时间
    $key = 'real_start_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $end = strtotime($data[$key]);
        if (0 < $end) {
            $task['ret'][$key] = $end;
        } else {
            $task['ret'][$key] = 0;
        }
    } else {
        $task['ret'][$key] = 0;
    }
    // 实际截止时间
    $key = 'real_end_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $end = strtotime($data[$key]);
        if (0 < $end) {
            $task['ret'][$key] = $end;
        } else {
            $task['ret'][$key] = 0;
        }
    } else {
        $task['ret'][$key] = 0;
    }
    // 任务备注
    $key = 'remark';
    if (isset($data[$key]) && !empty($data[$key])) {
        $task['ret'][$key] = $data[$key];
    } else {
        $task['ret'][$key] = '';
    }
    // 任务内容
    $key = 'content';
    if (isset($data[$key]) && !empty($data[$key])) {
        $task['ret'][$key] = $data[$key];
    } else {
        $task['ret'][$key] = '';
    }
    // 任务当前状态
    $key = 'status';
    if (isset($data[$key]) && 0 <= $data[$key]) {
        $task['ret'][$key] = $data[$key];
    } else {
        $task['error'][$key] = '任务当前状态是必选项';
    }
    return $task;
}
Пример #2
0
/**
 * 项目表单字段的验证
 *
 * @author yumin
 * @param $data 表单提交数组
 * @return $project 结果以及错误
 */
function validator_submit_project($data)
{
    // 综合验证
    if (empty($data)) {
        $project['error']['all'] = '服务器只是个传说,啥都没填写的话,就别提交了嘛!';
        return $project;
    }
    // 项目名称
    $key = 'projectname';
    if (isset($data[$key]) && !empty($data[$key])) {
        $project['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $project['error'][$key] = '项目名称是必填项';
    }
    // owner
    $key = 'owner';
    if (isset($data[$key]) && !empty($data[$key])) {
        $project['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $project['ret'][$key] = '';
    }
    // 负责人
    $key = 'owner_id';
    if (isset($data[$key]) && 0 < $data[$key]) {
        $project['ret'][$key] = $data[$key];
    } else {
        $project['error'][$key] = '负责人是必选项';
    }
    // 优先级
    $key = 'priority';
    if (isset($data[$key]) && 0 <= $data[$key]) {
        $project['ret'][$key] = $data[$key];
    } else {
        $project['error'][$key] = '优先级是必选项';
    }
    // 计划起始时间
    $key = 'plan_start_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $start = strtotime($data[$key]);
        if (0 < $start) {
            $project['ret'][$key] = $start;
        } else {
            $project['ret'][$key] = 0;
        }
    } else {
        $project['error'][$key] = '计划起始时间是必选项';
    }
    // 计划截止时间
    $key = 'plan_end_time';
    if (isset($data[$key]) && !empty($data[$key])) {
        $end = strtotime($data[$key]);
        if (0 < $end) {
            $project['ret'][$key] = $end;
        } else {
            $project['ret'][$key] = 0;
        }
    } else {
        $project['ret'][$key] = 0;
    }
    // Wiki地址
    $key = 'wiki';
    if (isset($data[$key]) && !empty($data[$key])) {
        $project['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $project['ret'][$key] = '';
    }
    // SVN地址
    $key = 'svn';
    if (isset($data[$key]) && !empty($data[$key])) {
        $project['ret'][$key] = get_safe_string($data[$key]);
    } else {
        $project['ret'][$key] = '';
    }
    // 项目备注
    $key = 'remark';
    if (isset($data[$key]) && !empty($data[$key])) {
        $project['ret'][$key] = $data[$key];
    } else {
        $project['ret'][$key] = '';
    }
    // 项目当前状态
    $key = 'status';
    if (isset($data[$key]) && 0 <= $data[$key]) {
        $project['ret'][$key] = $data[$key];
    } else {
        $project['error'][$key] = '项目当前状态是必选项';
    }
    return $project;
}