public static function isUserOwnEditor($editor_id)
 {
     global $db;
     $user_id = User::authService()['user_id'];
     if (User::isStudent()) {
         $db->join("assignment_group_student AGS", "AGS.group_id=AGC.group_id", "LEFT");
         $db->where("AGC.editor", $editor_id);
         $db->where("AGS.student_id", $user_id);
         $db->get("assignment_group_code AGC");
         if ($db->count == 0) {
             return false;
         } else {
             return true;
         }
     } elseif (User::isTeacher()) {
         $db->join('assignment A', 'A.assignment_id = SC.assignment_id', 'LEFT');
         $db->join('course C', 'C.course_id = A.course_id', 'LEFT');
         $db->where('C.user_id', $user_id);
         $db->get('assignment_sample_code SC');
         if ($db->count == 0) {
             return false;
         } else {
             return true;
         }
     }
 }
Example #2
0
 public function remove($editor_id)
 {
     global $db;
     $user_id = User::authService()['user_id'];
     if (!GlobalFunction::isUserOwnEditor($editor_id)) {
         die('no auth');
     }
     $db->where('editor', $editor_id);
     if (User::isTeacher()) {
         $db->delete('assignment_sample_code');
     } elseif (User::isStudent()) {
         $db->delete('assignment_group_code');
         $db->where('editor', $editor_id);
         $db->delete('assignment_history');
     }
     echo 1;
 }
Example #3
0
 public function course()
 {
     global $courseAPI, $db;
     $this->render("header");
     if (User::isStudent()) {
         render("student");
     } elseif (User::isTeacher()) {
         render("teacher");
     }
     render("footer");
 }
Example #4
0
             Yii::$app->user->isGuest ? (
                 ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login']]
             ) : 
                 (
                 '<li>'
                 . Html::beginForm(['/site/logout'], 'post')
                 . Html::submitButton(
                     Yii::t('app', 'Logout') . '(' . Yii::$app->user->identity->username . ')',
                     ['class' => 'btn btn-link']
                 )
                 . Html::endForm()
                 . '</li>'
             )
         ],
     ]);
 } else if (User::isTeacher(Yii::$app->user->id)) {
     echo Nav::widget([
         'options' => ['class' => 'navbar-nav navbar-right'],
         'items' => [
             ['label' => Yii::t('app', 'Course'), 'url' => ['/course/list']],
             ['label' => Yii::t('app', 'Course Manage'), 'url' => ['/course/manage']],
             ['label' => Yii::t('app', 'Tasks'), 'url' => ['/task/index']],
             ['label' => Yii::t('app', 'Zone'), 'url' => ['/user/zone']],
             ['label' => Yii::t('app', 'About'), 'url' => ['/site/about']],
             [
                 'label' => Yii::t('app', 'Widgets'),
                 'items' => [
                     [
                         'label' => Yii::$app->language == 'en-US' ?  '中文' : 'English',
                         'url' => ["/site/language"],
                         'linkOptions' => ['data-method' => 'post'],
Example #5
0
 /**
  * Client of self::allowStudents() and User::isTeacher(), this fn answers
  * the question: 'Can this \User $user access QM, given the current settings
  * configuration?'.
  *
  * @param User $user
  * @see User::$role User::$role
  * @see User::isTeacher()
  * @see QMConfig::allowStudents()
  * @return boolean  false if student, true if any other role
  */
 public function userRoleAllowed(User $user)
 {
     if (!$user->isTeacher()) {
         return $this->allowStudents();
     }
     return true;
 }
Example #6
0
 */
$sel_profile = "SELECT * FROM profili WHERE id = " . $user->getUid();
try {
    $res_profile = $db->executeQuery($sel_profile);
} catch (MySQLException $ex) {
    print "ko;" . $ex->getMessage();
    exit;
}
if ($res_profile->num_rows) {
    $profile = $res_profile->fetch_assoc();
    $user->setProfile($profile);
}
/**
 * subjects and classes : only for teachers
 */
if ($user->isTeacher()) {
    $sel_subject = "SELECT materia FROM docenti WHERE id_docente = " . $user->getUid();
    try {
        $res_materia = $db->executeQuery($sel_subject);
    } catch (MySQLException $ex) {
        print "ko;" . $ex->getMessage();
        exit;
    }
    $materia = $res_materia->fetch_assoc();
    $user->setSubject($materia['materia']);
    /**
     * populate the classes array
     */
    $classes = array();
    $sel_cdc = "SELECT classi.id_classe, CONCAT(classi.anno_corso, classi.sezione) AS classe, id_materia, coordinatore FROM classi, cdc WHERE classi.id_classe = cdc.id_classe AND id_docente = " . $user->getUid() . " AND id_anno = " . $_SESSION['__current_year__']->get_ID() . " ORDER BY classi.sezione, classi.anno_corso";
    try {