예제 #1
0
 /**
  * The student inserts this initially once he/she accepts a project offer
  * @param unknown $props
  * @param unknown $proposal_id
  * @return boolean|unknown
  */
 static function insertAgreement($props)
 {
     if (!$props) {
         drupal_set_message(t('Insert requested with empty (filtered) data set'), 'error');
         return false;
     }
     if (!isset($props['proposal_id'])) {
         drupal_set_message(t('Insert requested with no proposal set'), 'error');
         return false;
     }
     global $user;
     $txn = db_transaction();
     try {
         $proposal = objectToArray(Proposal::getInstance()->getProposalById($props['proposal_id']));
         $project = objectToArray(Project::getProjectById($proposal['pid']));
         if (!isset($props['student_id'])) {
             $props['student_id'] = $user->uid;
         }
         if (!isset($props['supervisor_id'])) {
             $props['supervisor_id'] = $proposal['supervisor_id'];
         }
         if (!isset($props['mentor_id'])) {
             $props['mentor_id'] = $project['mentor_id'];
         }
         $props['project_id'] = $proposal['pid'];
         if (!isset($props['description'])) {
             $props['description'] = '';
         }
         if (!isset($props['student_signed'])) {
             $props['student_signed'] = 0;
         }
         if (!isset($props['supervisor_signed'])) {
             $props['supervisor_signed'] = 0;
         }
         if (!isset($props['mentor_signed'])) {
             $props['mentor_signed'] = 0;
         }
         /*
         if (! testInput($props, array('owner_id', 'org_id', 'inst_id', 'supervisor_id','pid', 'title'))){
         	return FALSE;
         }
         */
         try {
             $id = db_insert(tableName(_AGREEMENT_OBJ))->fields($props)->execute();
         } catch (Exception $e) {
             drupal_set_message($e->getMessage(), 'error');
         }
         if ($id) {
             drupal_set_message(t('You have created your agreement: you can continue editing it later.'));
             return $id;
         } else {
             drupal_set_message(t('We could not add your agreement. ') . (_DEBUG ? '<br/>' . getDrupalMessages() : ""), 'error');
         }
         return $result;
     } catch (Exception $ex) {
         $txn->rollback();
         drupal_set_message(t('We could not add your agreement.') . (_DEBUG ? $ex->__toString() : ''), 'error');
     }
     return FALSE;
 }
예제 #2
0
function jsonResult($result, $msg = '', $type = '', $args = array(), $show_always = FALSE)
{
    if (!$msg) {
        //Get the messages set by drupal_set_messages, but if we pass deliberately null on, we expect no messages
        $msg = getDrupalMessages($type, $show_always);
    }
    $struct = $args;
    if ($result === 'error' || $result === false || is_null($result)) {
        $struct['result'] = 'error';
        $struct['error'] = $msg;
    } else {
        $struct['result'] = $result;
        $struct['msg'] = $msg;
    }
    echo json_encode($struct);
}
예제 #3
0
                 $mails[] = $mail;
                 $mails[$no]['to'] = $email;
                 $no++;
             }
         }
     } else {
         $mails[] = $mail;
         $mails[0]['to'] = $email;
     }
     // 		$mail['to'] = $email;//NEW
     // 		$mails[] = $mail;//NEW
     module_load_include('inc', 'vals_soc', 'includes/module/vals_soc.mail');
     if (vals_soc_send_emails_now($mails)) {
         echo successDiv(t('You sent your recommendation(s)'));
     } else {
         echo errorDiv(t('Something wrong with sending your recommendation(s): ') . getDrupalMessages('error'));
     }
     break;
 case 'rate':
     //do something
     if (!Users::isSuperVisor()) {
         echo t('You can only rate a project as supervisor.');
         return;
     }
     $rate = getRequestVar('rate');
     $id = getRequestVar('id');
     $table = tableName('supervisor_rate');
     $result = FALSE;
     $num_deleted = db_delete($table)->condition('pid', $id)->condition('uid', $GLOBALS['user']->uid)->execute();
     if ($num_deleted !== FALSE) {
         $result = db_insert($table)->fields(array('pid' => $id, 'uid' => $GLOBALS['user']->uid, 'rate' => $rate))->execute();
예제 #4
0
             $project = Project::getProjectById($project_id);
             $possible_supervisors = Project::getInterestedSupervisors($project_id);
             $form = drupal_get_form('vals_soc_proposal_form', $proposal, $target, $project_id, $possible_supervisors);
             if ($form) {
                 $prefix_form = "<div>" . tt('<b>Project</b> <i>%1$s</i>', $project['title']) . "</div>";
                 if ($result_format == 'json') {
                     jsonGoodResult($prefix_form . renderForm($form, $target, true));
                 } else {
                     echo $prefix_form;
                     renderForm($form, $target);
                 }
             } else {
                 if ($result_format == 'json') {
                     jsonBadResult();
                 } else {
                     echo errorDiv(getDrupalMessages('error', true));
                 }
             }
         }
     } else {
         jsonBadResult(t('No proposal identifier submitted!'));
     }
     break;
 case 'delete':
     $proposal_id = getRequestVar('proposal_id', null, 'post');
     $target = getRequestVar('target', 'our_content', 'post');
     if ($proposal_id) {
         $is_modal = $target !== 'our_content';
         //we need the container where the result is bad and we show an error msg
         $container = $is_modal ? 'admin_container' : 'our_content';
         $before = 'toc';
예제 #5
0
 static function insertProposal($props, $project_id)
 {
     if (!$props) {
         drupal_set_message(t('Insert requested with empty (filtered) data set'), 'error');
         return false;
     }
     global $user;
     $txn = db_transaction();
     try {
         $uid = $user->uid;
         if (!Users::isOfType(_STUDENT_TYPE, $uid)) {
             drupal_set_message(t('You must be a student to submit a proposal'), 'error');
             return false;
         }
         $project = Project::getProjectById($project_id);
         $student_details = Users::getStudentDetails($uid);
         $props['owner_id'] = $uid;
         $props['org_id'] = $project['org_id'];
         $props['inst_id'] = $student_details->inst_id;
         $props['supervisor_id'] = altSubValue($props, 'supervisor_id', 0) ?: $student_details->supervisor_id;
         $props['pid'] = $project['pid'];
         if (!isset($props['state'])) {
             $props['state'] = 'draft';
         }
         if (!testInput($props, array('owner_id', 'org_id', 'inst_id', 'supervisor_id', 'pid', 'title'))) {
             return FALSE;
         }
         try {
             // inserts where the field length is exceeded fails silently here
             // i.e. the date strinf is too long for the mysql field type
             $id = db_insert(tableName(_PROPOSAL_OBJ))->fields($props)->execute();
         } catch (Exception $e) {
             drupal_set_message($e->getMessage(), 'error');
         }
         if ($id) {
             //TODO: notify mentor???
             drupal_set_message(t('Note that you have only saved your proposal: you can continue editing it later.'));
             return $id;
         } else {
             drupal_set_message(t('We could not add your proposal. ') . (_DEBUG ? '<br/>' . getDrupalMessages() : ""), 'error');
         }
         return $result;
     } catch (Exception $ex) {
         $txn->rollback();
         drupal_set_message(t('We could not add your proposal.') . (_DEBUG ? $ex->__toString() : ''), 'error');
     }
     return FALSE;
 }