function removethreadsForEntity($entity_id, $entity_type) { try { $num_deleted = db_delete('soc_comments')->condition('entity_id', $entity_id)->condition('entity_type', $entity_type)->execute(); // fail silently if no record/s found } catch (Exception $e) { drupal_set_message(tt(' We could not delete the comments for this %1$s', t_type($entity_type)) . (_DEBUG ? $ex->getMessage() : ''), 'error'); return FALSE; } }
function renderOrganisation($type, $organisation = '', $organisation_owner = '', $target = '', $show_buttons = true) { if (!$organisation) { $organisation = Groups::getGroup($type, '', $organisation_owner); } $key_name = Groups::keyField($type); $id = $organisation->{$key_name}; if ($organisation) { $s = ''; if ($show_buttons && user_access('vals admin register')) { $pPath = request_path(); $edit_action = "onclick='ajaxCall(\"administration\", \"edit\", {type: \"{$type}\", id: {$id}, path: \"{$pPath}\", target: \"{$target}\"}, " . ($type == _STUDENT_GROUP ? "\"{$target}\");'" : "\"formResult\", \"html\", \"{$target}\");'"); $s .= "<div class='totheright'>"; $s .= "\t<input type='button' value='" . t('edit') . "' {$edit_action}/>"; // has the org signup period ended if so user cant add/delete entries, only edit if (vals_soc_access_check("dashboard/{$type}/administer/add_or_delete")) { $delete_action = "onclick='if(confirm(\"" . tt('Are you sure you want to delete this %1$s?', t_type($type)) . "\")){ajaxCall(\"administration\", \"delete\", {type: \"{$type}\", id: {$id}, path: \"{$pPath}\", target: \"{$target}\"}, \"refreshTabs\", \"json\", [\"{$type}\", \"{$target}\", \"administration\"]);}'"; $s .= "\t<input type='button' value='" . t('delete') . "' {$delete_action}/>"; } $s .= "</div>"; //$sub_type_user = ''; } $s .= formatMemberRecordNice($organisation, $type, $target); if ($type == _STUDENT_GROUP) { $s .= "<h2>" . t('Members') . "</h2>"; $students = Users::getStudents($id); $s .= renderStudents('', $students); } return $s; } else { return tt('You have no %1$s registered yet', $type); } }
break; case 'save': $type = altSubValue($_POST, 'type', ''); $id = altSubValue($_POST, 'id', ''); $draft = altSubValue($_POST, 'draft', false); $properties = Project::getInstance()->filterPostLite(Project::getInstance()->getKeylessFields(), $_POST); $properties['state'] = $draft ? 'draft' : 'pending'; if (!$id) { $new = $properties['org_id']; $result = Project::getInstance()->addProject($properties); } else { $new = false; $result = Project::getInstance()->changeProject($properties, $id); } if ($result) { echo json_encode(array('result' => TRUE, 'id' => $id, 'type' => $type, 'new_tab' => !$id ? $properties['org_id'] : 0, 'extra' => $mine ? array('mine' => 1) : '', 'msg' => ($id ? tt('You succesfully changed the data of your %1$s', t_type($type)) : tt('You succesfully added your %1$s', t_type($type))) . (_DEBUG ? showDrupalMessages() : ''))); } else { echo jsonBadResult(); } break; case 'show': $show_last = altSubValue($_POST, 'new_tab', false); $owner_only = altSubValue($_POST, 'mine', false); showProjectPage($show_last, $owner_only); break; case 'edit': $type = altSubValue($_POST, 'type', ''); $id = altSubValue($_POST, 'id', ''); $target = altSubValue($_POST, 'target', ''); $obj = Project::getProjectById($id, FALSE, NULL); if (!$obj) {
} break; case 'save': $type = altSubValue($_POST, 'type', ''); $id = altSubValue($_POST, 'id', ''); $show_action = altSubValue($_POST, 'show_action', ''); //TODO do some checks here if (!isValidOrganisationType($type)) { //&& ($type !== _PROJECT_OBJ) $result = NULL; drupal_set_message(tt('This is not a valid type: %s', $type), 'error'); echo jsonBadResult(); return; } $properties = Groups::filterPostByType($type, $_POST); if (!$id) { $new = true; $result = $type == _STUDENT_GROUP ? Groups::addStudentGroup($properties) : ($type == _PROJECT_OBJ ? Project::getInstance()->addProject($properties) : Groups::addGroup($properties, $type)); } else { $new = false; $result = Groups::changeGroup($type, $properties, $id); } if ($result) { echo json_encode(array('result' => TRUE, 'id' => $id, 'type' => $type, 'new_tab' => !$id ? $result : 0, 'show_action' => $show_action, 'msg' => ($id ? tt('You succesfully changed the data of your %1$s', t_type($type)) : tt('You succesfully added your %1$s', t_type($type))) . (_DEBUG ? showDrupalMessages() : ''))); } else { echo jsonBadResult(); } break; default: echo "No such action: " . $_GET['action']; }
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; } }
} echo json_encode(array('result' => TRUE, 'id' => $result, 'type' => $type, 'entity_id' => $entity_id, 'msg' => tt('You succesfully added a comment to this %1$s', t_type($type)) . (_DEBUG ? showDrupalMessages() : ''))); } else { echo jsonBadResult(); } break; case 'view': $type = altSubValue($_POST, 'type', 'comment'); $id = altSubValue($_POST, 'id'); $target = altSubValue($_POST, 'target', ''); if (!($id && $type && $target)) { die(t('There are missing arguments. Please inform the administrator of this mistake.')); } $post = ThreadedComments::getInstance()->getPostById($id); if (!$post) { echo tt('The post for this %1$s cannot be found', t_type($type)); } else { $entity_id = $post['entity_id']; $entity_type = $post['entity_type']; $threaded_comments = new ThreadUIBuilder($entity_id, $entity_type); echo $threaded_comments->renderSingleComment($post); } break; case 'viewall': if (getRole() != _ANONYMOUS_TYPE) { $type = altSubValue($_GET, 'type'); $id = altSubValue($_GET, 'id'); module_load_include('inc', 'vals_soc', 'includes/ui/comments/threaded_comments'); $content = initComments($id, $type); echo $content; }
function renderTabs($count, $tab_label, $target_label, $type, $data, $id = 0, $render_targets = false, $active_content = '', $active_tab = 1, $parent_type = 'administration') { ?> <ol id="toc"><?php $label_start = t($tab_label); $title = ""; $label_nr = 1; for ($t = 0; $t < $count; $t++) { $target = $target_label . ($t + 1); $tab_class = ''; $delete_tab = false; $pre = ""; $post = ""; if (isset($data[$t][7]) && $data[$t][7]) { $tab_class = ' class="right"'; if ($data[$t][7] == 'delete') { $delete_tab = true; $pre = "if (confirm('" . tt('Are you sure you want to delete this %1$s', t_type($type)) . "')){"; $post = "} else { Obj('{$target}').html('" . t('You canceled the delete request') . "')}"; } } $pre .= "Obj('{$target}').html('" . t('Loading, please wait...') . "');"; ?> <li<?php echo $tab_class; ?> ><a href="#tab_<?php echo $target; ?> " <?php //title, the tab is either: translated (arg=1), a numbered prefix (arg=0) or left as it is (arg <> 0,1 if ($data[$t][0] == 0) { //labels: 0 $link_text = "{$label_start} {$label_nr}"; $label_nr++; $title = " title = '" . $data[$t][1] . "' "; } elseif ($data[$t][0] == 1) { //translate 1 $link_text = t($data[$t][1]); $title = ""; } else { //unmodified 2 $link_text = $data[$t][1]; $title = ""; } echo $title; //onclick action if (isset($data[$t][2])) { $action = $data[$t][2]; $type = isset($data[$t][3]) ? $data[$t][3] : $type; $id = isset($data[$t][4]) ? $data[$t][4] : $id; //add extra get arguments if (isset($data[$t][5])) { $action .= "&" . $data[$t][5]; } $call_target = "'{$target}'"; echo "onclick=\"{$pre}ajaxCall('{$parent_type}', '{$action}', {type:'{$type}', id:{$id}, target:'{$target}'},"; if (isset($data[$t][6]) && $data[$t][6]) { $call_target = " 'formResult', 'html', ['{$target}', '{$parent_type}']"; } elseif ($delete_tab) { $call_target = " 'handleDeleteResult', 'json', ['admin_container', '{$parent_type}']"; } echo " {$call_target});{$post}\""; } ?> ><span><?php echo $link_text; ?> </span></a> </li> <?php } ?> </ol><?php if ($render_targets) { for ($i = 1; $i <= $count; $i++) { echo "<div id='{$target_label}{$i}' class='content'>" . "<div id='msg_{$target_label}{$i}'></div>" . ($i == $active_tab ? $active_content : '') . "</div>"; } } }