}
        unset($_POST);
        $form = drupal_get_form("vals_soc_project_form", $obj, $target);
        if ($originalPath) {
            $form['#action'] = url($originalPath);
        }
        // Process the submit button which uses ajax
        //$form['submit'] = ajax_pre_render_element($form['submit']);
        // Build renderable array
        // 		$build = array(
        // 				'form' => $form,
        // 				'#attached' => $form['submit']['#attached'], // This will attach all needed JS behaviors onto the page
        // 		);
        renderForm($form, $target);
        break;
    case 'delete':
        $type = altSubValue($_POST, 'type', '');
        $id = altSubValue($_POST, 'id', '');
        if (!isValidOrganisationType($type)) {
            echo jsonBadResult(t('There is no such type we can delete'));
        } elseif (count(Proposal::getProposalsPerProject($id))) {
            echo jsonBadResult(t('You cannot delte the project; there are already students working on a proposal for this project. You can still edit it though.'));
        } else {
            $result = Groups::removeGroup($type, $id);
            ThreadedComments::getInstance()->removethreadsForEntity($id, $type);
            echo $result ? jsonGoodResult(true, '', array('extra' => $mine ? array('mine' => 1) : '')) : jsonBadResult();
        }
        break;
    default:
        echo "No such action: " . $_GET['action'];
}
Beispiel #2
0
 static function removeGroup($type, $id)
 {
     if (!isValidOrganisationType($type)) {
         drupal_set_message(tt('This (%1$s) is not something you can remove.', t_type($type)), 'error');
         return FALSE;
     }
     if (!self::isOwner($type, $id)) {
         drupal_set_message(t('You are not authorised to perform this action'), 'error');
         return FALSE;
     }
     if (self::hasMembers($type, $id)) {
         drupal_set_message(tt('There are already members in this %1$s. You can still edit the %1$s though.', t_type($type)), 'error');
         return FALSE;
     }
     if ($type == _ORGANISATION_GROUP && db_query("SELECT pid FROM soc_projects WHERE org_id = {$id}")->rowCount()) {
         drupal_set_message(tt('There are already projects for this %1$s. You should delete these first.', t_type($type)), 'error');
         return FALSE;
     }
     if ($type == _INSTITUTE_GROUP && db_query("SELECT pid FROM soc_studentgroups WHERE inst_id = {$id}")->rowCount()) {
         drupal_set_message(tt('There are already student groups for this %1$s. You should delete these first.', t_type($type)), 'error');
         return FALSE;
     }
     try {
         if ($type != _PROJECT_OBJ) {
             $num_deleted2 = db_delete("soc_user_membership")->condition('group_id', $id)->condition('type', $type)->execute();
             if (!$num_deleted2) {
                 drupal_set_message(tt('The group had no members.', $type), 'status');
             }
             $subtype = $type == _ORGANISATION_GROUP ? _MENTOR_TYPE : ($type == _INSTITUTE_GROUP ? _SUPERVISOR_TYPE : _STUDENT_GROUP);
             $code_field = $subtype == _STUDENT_GROUP ? 'studentgroup_id' : 'entity_id';
             $num_deleted3 = db_delete("soc_codes")->condition(db_and()->condition($code_field, $id)->condition(db_or()->condition('type', $subtype)->condition('type', "{$type}_admin")))->execute();
             if (!$num_deleted3) {
                 drupal_set_message(tt('The %1$s had no code attached.', $type), 'status');
             }
         }
     } catch (Exception $e) {
         drupal_set_message(tt(' We could not delete the %1$s', t_type($type)) . (_DEBUG ? $ex->getMessage() : ''), 'error');
         return FALSE;
     }
     try {
         $num_deleted = db_delete(tableName($type))->condition(self::keyField($type), $id)->execute();
         if ($num_deleted) {
             drupal_set_message(tt('The %1$s has been deleted.', $type), 'status');
             return TRUE;
         } else {
             drupal_set_message(tt('The %1$s seems to have been deleted already, refresh your screen to see if this is true.', $type), 'error');
             return 0;
         }
     } catch (Exception $e) {
         drupal_set_message(tt(' We could not delete the %1$s', t_type($type)) . (_DEBUG ? $ex->getMessage() : ''), 'error');
         return FALSE;
     }
 }