/** * removeUser - controls removing a user from a group. * * Users can remove themselves. * * @param int The ID of the user to remove. * @return boolean success. */ function removeUser($user_id) { global $SYS, $sys_database_type; if ($user_id == user_getid()) { //users can remove themselves //everyone else must be a project admin } else { $perm =& $this->getPermission(session_get_user()); if (!$perm || !is_object($perm) || !$perm->isAdmin()) { $this->setPermissionDeniedError(); return false; } } db_begin(); $res = db_query("DELETE FROM user_group \n\t\t\tWHERE group_id='" . $this->getID() . "' \n\t\t\tAND user_id='{$user_id}'"); if (!$res || db_affected_rows($res) < 1) { $this->setError(sprintf(_('ERROR: User not removed: %s'), db_error())); db_rollback(); return false; } else { // // reassign open artifacts to id=100 // $res = db_query("UPDATE artifact SET assigned_to='100' \n\t\t\t\tWHERE group_artifact_id \n\t\t\t\tIN (SELECT group_artifact_id \n\t\t\t\tFROM artifact_group_list \n\t\t\t\tWHERE group_id='" . $this->getID() . "') \n\t\t\t\tAND status_id='1' AND assigned_to='{$user_id}'"); if (!$res) { $this->setError(sprintf(_('ERROR: DB: artifact: %s'), db_error())); db_rollback(); return false; } // // reassign open tasks to id=100 // first have to purge any assignments that would cause // conflict with existing assignment to 100 // if ($sys_database_type == 'mysql') { $res = db_mquery("\n\t\t\t\t\tSELECT pt.project_task_id \n\t\t\t\t\tFROM project_task pt, project_group_list pgl, project_assigned_to pat \n\t\t\t\t\tWHERE pt.group_project_id = pgl.group_project_id \n\t\t\t\t\tAND pat.project_task_id=pt.project_task_id\n\t\t\t\t\tAND pt.status_id='1' AND pgl.group_id='" . $this->getID() . "'\n\t\t\t\t\tAND pat.assigned_to_id='{$user_id}' INTO @task_list;\n\t\t\t\t\tDELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'"); if ($res) { $res = db_next_result(); } } else { $res = db_query("DELETE FROM project_assigned_to\n\t\t\t\t\tWHERE project_task_id IN (SELECT pt.project_task_id \n\t\t\t\t\tFROM project_task pt, project_group_list pgl, project_assigned_to pat \n\t\t\t\t\tWHERE pt.group_project_id = pgl.group_project_id \n\t\t\t\t\tAND pat.project_task_id=pt.project_task_id\n\t\t\t\t\tAND pt.status_id='1' AND pgl.group_id='" . $this->getID() . "'\n\t\t\t\t\tAND pat.assigned_to_id='{$user_id}') \n\t\t\t\t\tAND assigned_to_id='100'"); } if (!$res) { $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'), 1, db_error())); db_rollback(); return false; } $res = db_query("UPDATE project_assigned_to SET assigned_to_id='100' \n\t\t\t\tWHERE project_task_id IN (SELECT pt.project_task_id \n\t\t\t\tFROM project_task pt, project_group_list pgl \n\t\t\t\tWHERE pt.group_project_id = pgl.group_project_id \n\t\t\t\tAND pt.status_id='1' AND pgl.group_id='" . $this->getID() . "') \n\t\t\t\tAND assigned_to_id='{$user_id}'"); if (!$res) { $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'), 2, db_error())); db_rollback(); return false; } // // Remove user from system // //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>"; if (!$SYS->sysGroupRemoveUser($this->getID(), $user_id)) { $this->setError($SYS->getErrorMessage()); db_rollback(); return false; } //audit trail $this->addHistory('Removed User', $user_id); } db_commit(); return true; }
require $gfcommon . 'include/cron_utils.php'; $err = ''; $threshhold = '1.6'; db_begin(); db_query("DELETE FROM user_metric0"); $err .= db_error(); if ($sys_database_type != 'mysql') { db_query("select setval('user_metric0_pk_seq',1)"); $err .= db_error(); } db_query("INSERT INTO user_metric0 \n(user_id,times_ranked,avg_raters_importance,avg_rating,metric,percentile,importance_factor)\nSELECT user_id,5,1.25,3,0,0,1.25\nFROM user_group\nWHERE\nuser_group.group_id='{$sys_peer_rating_group}'\nAND user_group.admin_flags='A';"); $err .= db_error(); db_query("UPDATE user_metric0 SET ranking=ranking-1"); if ($sys_database_type == 'mysql') { $sql = "\n\tSELECT count(*) FROM user_metric0 INTO @total;\n\tUPDATE user_metric0 SET\n\tmetric=(log(times_ranked)*avg_rating),\n\tpercentile=(100-(100*(ranking-1.0)/@total));"; db_mquery($sql); $err .= db_error(); db_next_result(); $err .= db_error(); } else { $sql = "UPDATE user_metric0 SET\n\tmetric=(log(times_ranked::float)*avg_rating::float)::float,\n\tpercentile=(100-(100*((ranking::float-1)/(select count(*) from user_metric0))))::float;"; db_query($sql); $err .= db_error(); } if ($sys_database_type == 'mysql') { $sql = "UPDATE user_metric0 SET importance_factor=(1+((percentile/100.0)*.5));"; } else { $sql = "UPDATE user_metric0 SET importance_factor=(1+((percentile::float/100)*.5))::float;"; } db_query($sql); $err .= db_error();
/** * getNextThreadID - The next thread_id for a new top in this forum. * * @return int The next thread_id #. */ function getNextThreadID() { global $sys_database_type; if ($sys_database_type == "mysql") { $sql = "call newval('forum_thread_seq', @res)"; $result = db_mquery($sql); if (!$result) { echo db_error(); return false; } $sql = "select @res"; } else { $sql = "SELECT nextval('forum_thread_seq')"; } $result = db_query($sql); if (!$result || db_numrows($result) < 1) { echo db_error(); return false; } return db_result($result, 0, 0); }
} } if (getStringFromRequest('init')) { // now we're going to check if there's a XX-init.sql file and run it $db_init = $sys_plugins_path . '/' . $pluginname . '/db/' . $pluginname . '-init-' . $sys_database_type . '.sql'; if (!is_file($db_init)) { $db_init = $sys_plugins_path . '/' . $pluginname . '/db/' . $pluginname . '-init.sql'; if (!is_file($db_init)) { $db_init = 0; } } if ($db_init) { $arch = file_get_contents($db_init); $arch = preg_replace('/(INSERT INTO plugins.*$)/', '', $arch); // remove the line that inserts into plugins table, we are already doing that (and this would return error otherwise) $res = db_mquery($arch); if ($res) { while ($res) { db_free_result($res); $res = db_next_result(); } } else { $feedback .= _('Initialisation error<br />Database said: ') . db_error(); } } //we check for a php script if (is_file($sys_plugins_path . '/' . $pluginname . '/script/' . $pluginname . '-init.php')) { include $sys_plugins_path . '/' . $pluginname . '/script/' . $pluginname . '-init.php'; } else { } }