public static function install($data, &$fail, &$errno, &$error)
 {
     if (!$fail && (isset($data['action']) && $data['action'] == 'update' || isset($data['DB']['db_user_override_operator']) && $data['DB']['db_user_override_operator'] === 'override')) {
         $oldName = $data['DB']['db_name'];
         $data['DB']['db_name'] = null;
         $sql = "DROP USER '{$data['DB']['db_user_operator']}'@'%';";
         $sql2 = "DROP USER '{$data['DB']['db_user_operator']}'@'localhost';";
         $result = DBRequest::request2($sql, false, $data);
         $result = DBRequest::request2($sql2, false, $data);
         /*if ($result["errno"] !== 0){
               $fail = true; $errno = $result["errno"];$error = isset($result["error"]) ? $result["error"] : '';
           }*/
         $data['DB']['db_name'] = $oldName;
     }
     $userExists = false;
     if (!$fail) {
         $oldName = $data['DB']['db_name'];
         $data['DB']['db_name'] = null;
         $sql = "SELECT count(1) as 'exists' FROM mysql.user WHERE user = '******'DB']['db_user_operator']}';";
         $result = DBRequest::request($sql, false, $data);
         if ($result["errno"] !== 0 || !isset($result["content"])) {
             $fail = true;
             $errno = $result["errno"];
             $error = isset($result["error"]) ? $result["error"] : '';
         } else {
             $result = DBJson::getRows($result['content']);
             if (count($result) > 0 && isset($result[0]['exists']) && $result[0]['exists'] > 0) {
                 $userExists = true;
             }
         }
         $data['DB']['db_name'] = $oldName;
     }
     if (!$fail && !$userExists) {
         $oldName = $data['DB']['db_name'];
         $data['DB']['db_name'] = null;
         $sql = "GRANT CREATE VIEW,EXECUTE,ALTER ROUTINE,CREATE ROUTINE,SHOW VIEW,CREATE TEMPORARY TABLES,INDEX,ALTER,SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,TRIGGER " . "ON `{$oldName}`.* " . "TO '{$data['DB']['db_user_operator']}'@'%' " . "IDENTIFIED BY '{$data['DB']['db_passwd_operator']}';";
         $sql .= "GRANT CREATE VIEW,EXECUTE,ALTER ROUTINE,CREATE ROUTINE,SHOW VIEW,CREATE TEMPORARY TABLES,INDEX,ALTER,SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,TRIGGER " . "ON `{$oldName}`.* " . "TO '{$data['DB']['db_user_operator']}'@'localhost' " . "IDENTIFIED BY '{$data['DB']['db_passwd_operator']}';";
         $result = DBRequest::request2($sql, false, $data);
         if ($result[0]["errno"] !== 0 && (count($result) < 2 || $result[1]["errno"] !== 0)) {
             $fail = true;
             $errno = $result[0]["errno"];
             $error = isset($result[0]["error"]) ? $result[0]["error"] : '';
         }
         $data['DB']['db_name'] = $oldName;
     } elseif ($userExists) {
         $fail = true;
         $errno = 0;
         $error = 'user already exists';
     }
     return null;
 }
Beispiel #2
0
 /**
  * converts an object to insert/update data
  *
  * @return a comma separated string e.g. "a=1,b=2"
  */
 public function getInsertData($doubleEscaped = false)
 {
     $values = '';
     if ($this->status != null) {
         $this->addInsertData($values, 'CS_status', DBJson::mysql_real_escape_string($this->status));
     }
     if ($this->course != null && $this->course->getId() != null) {
         $this->addInsertData($values, 'C_id', DBJson::mysql_real_escape_string($this->course->getId()));
     }
     if ($values != '') {
         $values = substr($values, 1);
     }
     return $doubleEscaped ? DBJson::mysql_real_escape_string($values) : $values;
 }
Beispiel #3
0
 public function get($functionName, $linkName, $params = array(), $singleResult = false, $checkSession = true)
 {
     // in diesem Beispiel wird der Name, welcher in der Commands.json für diesen Funktionsaufruf angegeben wurde,
     // direkt Verwendet, um einen gleichnamigen Ausgang der Component.json anzusprechen und den dort
     // angegeben Aufruf auzulösen (wobei courseid entsprechend ersetzt wird)
     // diese Funktion soll aufgerufen werden, wenn unsere Anfrage an die Datenbank positiv war
     $positive = function ($input, $singleResult) {
         $result = Model::isEmpty();
         $result['content'] = array();
         foreach ($input as $inp) {
             if ($inp->getNumRows() > 0) {
                 // extract course data from db answer
                 $result['content'] = array_merge($result['content'], Course::ExtractCourse($inp->getResponse(), $singleResult));
                 $result['status'] = 200;
             }
         }
         return $result;
     };
     // hier wird eine MySql stored-procedure aufgerufen
     // dabei haben die aufzurufen Befehle die Form /funktionsname/:idA/:idB  (stehen in der Component.json)
     // dabei werden idA und idB durch die Werte in $params ersetzt Bsp.: $params = array("idA"=>2, "idB"=>3)
     $params = DBJson::mysql_real_escape_string($params);
     return $this->_component->call($linkName, $params, '', 200, $positive, array($singleResult), 'Model::isProblem', array(), 'Query');
 }
Beispiel #4
0
 public static function ExtractInvitation($data, $singleResult = false, $LeaderExtension = '', $MemberExtension = '', $InvitationExtension = '', $isResult = true)
 {
     // generates an assoc array of users by using a defined list of
     // its attributes
     $leader = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $LeaderExtension);
     // generates an assoc array of users by using a defined list of
     // its attributes
     $member = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $MemberExtension . '2');
     // generates an assoc array of invitations by using a defined list of
     // its attributes
     $invitations = DBJson::getObjectsByAttributes($data, Invitation::getDBPrimaryKey(), Invitation::getDBConvert(), $InvitationExtension);
     // concatenates the invitations and the associated invitation leader
     $res = DBJson::concatObjectListsSingleResult($data, $invitations, Invitation::getDBPrimaryKey(), Invitation::getDBConvert()['U_leader'], $leader, User::getDBPrimaryKey(), $InvitationExtension, $LeaderExtension);
     // concatenates the invitations and the associated invitation member
     $res = DBJson::concatObjectListsSingleResult($data, $res, Invitation::getDBPrimaryKey(), Invitation::getDBConvert()['U_member'], $member, User::getDBPrimaryKey(), $MemberExtension . '2', $InvitationExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Invitation::decodeInvitation($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #5
0
 public function getAmountOfExpiredTransactions($name = '', $courseid)
 {
     $this->loadConfig($name);
     $name = ($name === '' ? '' : '_') . $name;
     Logger::Log('starts GET GetAmountOfExpiredTransactions', LogLevel::DEBUG);
     $courseid = DBJson::mysql_real_escape_string($courseid);
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/procedures/GetAmountOfExpiredTransactions.sql', array('courseid' => $courseid, 'name' => $name));
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         $result = $query->getResponse();
         foreach ($result as &$res) {
             $res['component'] = $this->_conf->getName();
         }
         $this->_app->response->setStatus(200);
         $this->_app->response->setBody(json_encode($result));
     } else {
         Logger::Log('GET GetAmountOfExpiredTransactions failed', LogLevel::ERROR);
         $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
         $this->_app->response->setBody('');
         $this->_app->stop();
     }
 }
Beispiel #6
0
 /**
  * Adds the component to a course
  *
  * Called when this component receives an HTTP POST request to
  * (/:preChoice(/:preForm(/:preExercise)))/course(/).
  *
  * @param int $preChoice A optional prefix for the Choice table.
  * @param int $preForm A optional prefix for the Form table.
  * @param int $preExercise A optional prefix for the Exercise table.
  */
 public function addCourse($preChoice = '', $preForm = '', $preExercise = '')
 {
     $this->loadConfig($preChoice, $preForm, $preExercise);
     $preChoice = ($preChoice === '' ? '' : '_') . $preChoice;
     $preForm = ($preForm === '' ? '' : '_') . $preForm;
     $preExercise = ($preExercise === '' ? '' : '_') . $preExercise;
     Logger::Log('starts POST AddCourse', LogLevel::DEBUG);
     // decode the received course data, as an object
     $insert = Course::decodeCourse($this->_app->request->getBody());
     $preChoice = DBJson::mysql_real_escape_string($preChoice);
     $preForm = DBJson::mysql_real_escape_string($preForm);
     $preExercise = DBJson::mysql_real_escape_string($preExercise);
     // always been an array
     $arr = true;
     if (!is_array($insert)) {
         $insert = array($insert);
         $arr = false;
     }
     // this array contains the indices of the inserted objects
     $res = array();
     foreach ($insert as $in) {
         // starts a query, by using a given file
         $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddCourse.sql', array('object' => $in, 'preChoice' => $preChoice, 'preForm' => $preForm, 'preExercise' => $preExercise));
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $queryResult = Query::decodeQuery($result['content']);
             $res[] = $in;
             $this->_app->response->setStatus(201);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             Logger::Log('POST AddCourse failed', LogLevel::ERROR);
             $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->_app->response->setBody(Course::encodeCourse($res));
             $this->_app->stop();
         }
     }
     if (!$arr && count($res) == 1) {
         $this->_app->response->setBody(Course::encodeCourse($res[0]));
     } else {
         $this->_app->response->setBody(Course::encodeCourse($res));
     }
 }
Beispiel #7
0
 public static function request2($sqlStatement, $checkSession, $config = null, $useDbOperator = false)
 {
     if ($config === null) {
         // loads the mysql server config from file
         $config = parse_ini_file('config.ini', TRUE);
     }
     //ini_set('mysql.connect_timeout','60');
     // creates a new connection to database
     if (!isset($config['ZV']['zv_type']) || isset($config['ZV']['zv_type']) && $config['ZV']['zv_type'] == 'local') {
         $path = strpos($config['PL']['urlExtern'], $config['DB']['db_path']) === false ? $config['DB']['db_path'] : 'localhost';
     } else {
         $path = $config['DB']['db_path'];
     }
     if (!$useDbOperator) {
         $dbconn = @mysqli_connect($path, $config['DB']['db_user'], $config['DB']['db_passwd'], $config['DB']['db_name']);
     } else {
         $dbconn = @mysqli_connect($path, $config['DB']['db_user_operator'], $config['DB']['db_passwd_operator'], $config['DB']['db_name']);
     }
     if (!$dbconn) {
         $query_result['errno'] = 10;
         return $query_result;
     }
     // use UTF8
     mysqli_set_charset($dbconn, "utf8");
     $currentTime = $_SERVER['REQUEST_TIME'];
     // check session
     ///if (error_reporting() & E_NOTICE)
     $checkSession = false;
     // remove the comment this line to disable the session examination
     // Storing whether or not a session condition is not satisfied
     $sessionFail = false;
     if ($checkSession === true) {
         Logger::Log('starts session validation', LogLevel::DEBUG);
         if (isset($_SERVER['HTTP_SESSION']) && isset($_SERVER['HTTP_USER']) && isset($_SERVER['HTTP_DATE']) && ctype_digit($_SERVER['HTTP_USER']) && (int) $_SERVER['REQUEST_TIME'] <= (int) $_SERVER['HTTP_DATE'] + 45 * 60) {
             $content = mysqli_query($dbconn, 'select SE_sessionID from Session where U_id = ' . $_SERVER['HTTP_USER']);
             // evaluates the session
             $errno = mysqli_errno($dbconn);
             if ($errno == 0 && gettype($content) != 'boolean') {
                 $data = DBJson::getRows2($content);
                 if ($data != null && $data[0]['SE_sessionID'] == $_SERVER['HTTP_SESSION']) {
                     $sessionFail = false;
                 } else {
                     $sessionFail = true;
                 }
             } else {
                 $sessionFail = true;
             }
         } else {
             $sessionFail = true;
         }
     }
     // if a condition is not met, the request is invalid
     if ($sessionFail == true) {
         $query_result['content'] = '';
         $query_result['errno'] = 401;
         $query_result['error'] = 'access denied';
         $query_result['numRows'] = 0;
         mysqli_close($dbconn);
         $dbconn = null;
         return array($query_result);
     }
     // performs the request
     $answ = mysqli_multi_query($dbconn, $sqlStatement);
     $query_result = array();
     if ($answ === false) {
         $result = array();
         $result['affectedRows'] = mysqli_affected_rows($dbconn);
         $result['insertId'] = mysqli_insert_id($dbconn);
         $result['errno'] = mysqli_errno($dbconn);
         $result['error'] = mysqli_error($dbconn);
         $query_result[] = $result;
     } else {
         do {
             $result = array();
             $res = null;
             if ($res = mysqli_use_result($dbconn)) {
                 $hash = '';
                 $result['content'] = DBJson::getRows2($res, $hash);
                 $result['hash'] = $hash;
                 $result['numRows'] = count($result['content']);
                 // evaluates the request
                 $result['affectedRows'] = mysqli_affected_rows($dbconn);
                 $result['insertId'] = mysqli_insert_id($dbconn);
                 $result['errno'] = mysqli_errno($dbconn);
                 $result['error'] = mysqli_error($dbconn);
                 mysqli_free_result($res);
             } else {
                 $hash = '';
                 $result['content'] = null;
                 $result['hash'] = $hash;
                 $result['affectedRows'] = mysqli_affected_rows($dbconn);
                 $result['insertId'] = mysqli_insert_id($dbconn);
                 $result['errno'] = mysqli_errno($dbconn);
                 $result['error'] = mysqli_error($dbconn);
             }
             $query_result[] = $result;
         } while (mysqli_more_results($dbconn) && mysqli_next_result($dbconn));
     }
     // closes the connection and returns the result
     mysqli_close($dbconn);
     $dbconn = null;
     return $query_result;
 }
Beispiel #8
0
 public static function ExtractSubmission($data, $singleResult = false, $FileExtension = '', $SubmissionExtension = '', $isResult = true)
 {
     // generates an assoc array of files by using a defined list of
     // its attributes
     $files = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $FileExtension);
     // generates an assoc array of submissions by using a defined list of
     // its attributes
     $submissions = DBJson::getObjectsByAttributes($data, Submission::getDBPrimaryKey(), Submission::getDBConvert(), $SubmissionExtension);
     // sets the selectedForGroup attribute
     foreach ($submissions as &$submission) {
         if (isset($submission['selectedForGroup'])) {
             if (isset($submission['id']) && $submission['id'] == $submission['selectedForGroup']) {
                 $submission['selectedForGroup'] = (string) 1;
             } else {
                 unset($submission['selectedForGroup']);
             }
         }
     }
     // concatenates the submissions and the associated files
     $res = DBJson::concatObjectListsSingleResult($data, $submissions, Submission::getDBPrimaryKey(), Submission::getDBConvert()['S_file'], $files, File::getDBPrimaryKey(), $FileExtension, $SubmissionExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Submission::decodeSubmission($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #9
0
 /**
  * Removes the component from a given course
  */
 public function deleteCourse($pre = '', $courseid)
 {
     $this->loadConfig($pre);
     $pre = ($pre === '' ? '' : '_') . $pre;
     Logger::Log('starts DELETE DeleteCourse', LogLevel::DEBUG);
     $courseid = DBJson::mysql_real_escape_string($courseid);
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/DeleteCourse.sql', array('courseid' => $courseid, 'pre' => $pre));
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $this->_app->response->setStatus(201);
         $this->_app->response->setBody('');
         if (isset($result['headers']['Content-Type'])) {
             $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
         }
     } else {
         Logger::Log('DELETE DeleteCourse failed', LogLevel::ERROR);
         $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
         $this->_app->response->setBody('');
         $this->_app->stop();
     }
 }
Beispiel #10
0
 public static function ExtractExerciseFileType($data, $singleResult = false, $FileTypeExtension = '', $isResult = true)
 {
     // generates an assoc array of an exercise file type by using a defined
     // list of its attributes
     $res = DBJson::getResultObjectsByAttributes($data, ExerciseFileType::getDBPrimaryKey(), ExerciseFileType::getDBConvert(), $FileTypeExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = ExerciseFileType::decodeExerciseFileType($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #11
0
 private function updateEmail()
 {
     if ($this->get_request_method() !== 'POST') {
         $this->response('', API::STATUS_NOT_ACCEPTABLE);
     }
     $json = json_decode(file_get_contents("php://input"), true);
     // obtendo o id do objeto:
     $idEmail = (int) $json['id'];
     // obtendo o json do objeto com os novos valores:
     $json_objeto = $json['email'];
     // convertendo o json do objeto para um objeto:
     $objeto = DBJson::jsonToEmail($json_objeto);
     // garantindo que nao haja tentativa de alteracao do id do objeto:
     $objeto->setId($idEmail);
     // corrigindo os campos do objeto:
     // comentado: ao corrigir os campos null, estava alterando campos no banco de dados que nao havia sido
     //            passados pelo JSON, fazendo com que eles ficassem em branco no banco de dados.
     //$objeto->correctNullFields();
     // AQUI JA TEMOS O 'ID' E O 'OBJETO' COM OS NOVOS VALORES!
     if (DBObject::updateEmail($objeto)) {
         $success = array('status' => 'Sucesso', 'msg' => 'Email (' . $idEmail . ') atualizado com sucesso.');
         $this->response($this->json($success), API::STATUS_OK);
     } else {
         $this->response('', API::STATUS_NOT_FOUND);
     }
 }
Beispiel #12
0
 /**
  * converts an object to insert/update data
  *
  * @return a comma separated string e.g. "a=1,b=2"
  */
 public function getInsertData($doubleEscaped = false)
 {
     $values = '';
     if ($this->id != null) {
         $this->addInsertData($values, 'CL_id', DBJson::mysql_real_escape_string($this->id));
     }
     if ($this->name != null) {
         $this->addInsertData($values, 'CL_name', DBJson::mysql_real_escape_string($this->name));
     }
     if ($this->owner != null) {
         $this->addInsertData($values, 'CO_id_owner', DBJson::mysql_real_escape_string($this->owner));
     }
     if ($this->target != null) {
         $this->addInsertData($values, 'CO_id_target', DBJson::mysql_real_escape_string($this->target));
     }
     if ($this->relevanz != null) {
         $this->addInsertData($values, 'CL_relevanz', DBJson::mysql_real_escape_string($this->relevanz));
     }
     if ($this->priority != null) {
         $this->addInsertData($values, 'CL_priority', DBJson::mysql_real_escape_string($this->priority));
     }
     if ($this->path != null) {
         $this->addInsertData($values, 'CL_path', DBJson::mysql_real_escape_string($this->path));
     }
     if ($values != '') {
         $values = substr($values, 1);
     }
     return $doubleEscaped ? DBJson::mysql_real_escape_string($values) : $values;
 }
Beispiel #13
0
 /**
  * @param $objeto O email.
  * @param bool|false $noContato Se a lista de contatos do email nao deve ser incluida no json.
  * @return array O email no formato json.
  */
 public static function emailToJson($objeto, $noContato = false)
 {
     $json = array('id' => $objeto->getId(), 'endereco' => $objeto->getEndereco());
     if (!$noContato) {
         $json['contato'] = DBJson::contatoToJson($objeto->getContato(), false, true);
     }
     return $json;
 }
Beispiel #14
0
 public static function ExtractGroup($data, $singleResult = false, $LeaderExtension = '', $MemberExtension = '', $GroupExtension = '', $isResult = true)
 {
     // generates an assoc array of an user by using a defined list of
     // its attributes
     $leader = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $LeaderExtension);
     // generates an assoc array of users by using a defined list of
     // its attributes
     $member = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $MemberExtension . '2');
     // generates an assoc array of groups by using a defined list of
     // its attributes
     $groups = DBJson::getObjectsByAttributes($data, Group::getDBPrimaryKey(), Group::getDBConvert(), $GroupExtension);
     // concatenates the groups and the associated group leader
     $res = DBJson::concatObjectListsSingleResult($data, $groups, Group::getDBPrimaryKey(), Group::getDBConvert()['U_leader'], $leader, User::getDBPrimaryKey(), $LeaderExtension, $GroupExtension);
     // concatenates the groups and the associated group member
     $res = DBJson::concatResultObjectLists($data, $res, Group::getDBPrimaryKey(), Group::getDBConvert()['U_member'], $member, User::getDBPrimaryKey(), $MemberExtension . '2', $GroupExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = Group::decodeGroup($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #15
0
 public static function ExtractForm($data, $singleResult = false, $FormsExtension = '', $ChoiceExtension = '', $isResult = true)
 {
     // generates an assoc array of an forms by using a defined
     // list of its attributes
     $forms = DBJson::getObjectsByAttributes($data, Form::getDBPrimaryKey(), Form::getDBConvert(), $FormsExtension);
     // generates an assoc array of choices by using a defined
     // list of its attributes
     $choices = DBJson::getObjectsByAttributes($data, Choice::getDBPrimaryKey(), Choice::getDBConvert(), $ChoiceExtension);
     // concatenates the forms and the associated choices
     $res = DBJson::concatObjectListResult($data, $forms, Form::getDBPrimaryKey(), Form::getDBConvert()['FO_choices'], $choices, Choice::getDBPrimaryKey(), $ChoiceExtension, $FormsExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Form::decodeForm($res, false);
         if ($singleResult) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #16
0
 public function getTableReferences()
 {
     Logger::Log('starts GET GetTableReferences', LogLevel::DEBUG);
     if (!file_exists(dirname(__FILE__) . '/config.ini')) {
         $this->_app->response->setStatus(409);
         $this->_app->stop();
     }
     $conf = parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE);
     // starts a query
     ob_start();
     eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/GetTableReferences.sql'));
     $sql = ob_get_contents();
     ob_end_clean();
     $result = DBRequest::request($sql, false, $conf);
     // checks the correctness of the query
     if ((!isset($result['errno']) || !$result['errno']) && $result['content']) {
         $data = DBJson::getRows($result['content']);
         $res = array();
         foreach ($data as $dat) {
             if (!isset($res)) {
                 $res[$dat['table_name']] = array();
             }
             $res[$dat['table_name']][] = $dat['referenced_table_name'];
         }
         $this->_app->response->setStatus(200);
         $this->_app->response->setBody(json_encode($res));
     } else {
         Logger::Log('GET GetTableReferences failed', LogLevel::ERROR);
         $this->_app->response->setStatus(409);
         $this->_app->response->setBody('');
         $this->_app->stop();
     }
 }
Beispiel #17
0
 public static function ExtractFile($data, $singleResult = false)
 {
     // generates an assoc array of files by using a defined list of
     // its attributes
     $res = DBJson::getResultObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert());
     $res = File::decodeFile($res, false);
     if ($singleResult == true) {
         // only one object as result
         if (count($res) > 0) {
             $res = $res[0];
         }
     }
     return $res;
 }
Beispiel #18
0
 public function get($functionName, $linkName, $params = array(), $checkSession = true)
 {
     $positive = function ($input) {
         //$input = $input[count($input)-1];
         $result = Model::isEmpty();
         $result['content'] = array();
         foreach ($input as $inp) {
             if ($inp->getNumRows() > 0) {
                 // extract Invitation data from db answer
                 $res = Invitation::ExtractInvitation($inp->getResponse(), false);
                 $result['content'] = array_merge($result['content'], is_array($res) ? $res : array($res));
                 $result['status'] = 200;
             }
         }
         return $result;
     };
     $params = DBJson::mysql_real_escape_string($params);
     return $this->_component->call($linkName, $params, '', 200, $positive, array(), 'Model::isProblem', array(), 'Query');
 }
Beispiel #19
0
 public static function ExtractExerciseSheet($data, $singleResult = false, $SheetExtension = '', $SheetFileExtension = '', $SheetSolutionExtension = '', $isResult = true)
 {
     // generates an assoc array of an exercise sheet by using a defined list of its attributes
     $exerciseSheet = DBJson::getObjectsByAttributes($data, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert(), $SheetExtension);
     // generates an assoc array of an file by using a defined list of its attributes
     $exerciseSheetFile = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $SheetFileExtension);
     // generates an assoc array of an file by using a defined list of its attributes
     $sampleSolutions = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $SheetSolutionExtension . '2');
     // concatenates the exercise sheet and the associated sample solution
     $res = DBJson::concatObjectListsSingleResult($data, $exerciseSheet, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert()['F_id_file'], $exerciseSheetFile, File::getDBPrimaryKey(), $SheetFileExtension, $SheetExtension);
     // concatenates the exercise sheet and the associated exercise sheet file
     $res = DBJson::concatObjectListsSingleResult($data, $res, ExerciseSheet::getDBPrimaryKey(), ExerciseSheet::getDBConvert()['F_id_sampleSolution'], $sampleSolutions, File::getDBPrimaryKey(), $SheetSolutionExtension . '2', $SheetExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = ExerciseSheet::decodeExerciseSheet($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #20
0
 public static function ExtractBEISPIEL($data)
 {
     $res = DBJson::getResultObjectsByAttributes($data, BEISPIEL::getDBPrimaryKey(), BEISPIEL::getDBConvert());
     return $res;
 }
Beispiel #21
0
 public static function ExtractCourseStatus($data, $singleResult = false, $UserExtension = '', $CourseStatusExtension = '', $CourseExtension = '', $isResult = true)
 {
     // generates an assoc array of a user by using a defined list of its
     // attributes
     $user = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $UserExtension);
     // generates an assoc array of course stats by using a defined list of
     // its attributes
     $courseStatus = DBJson::getObjectsByAttributes($data, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert(), $CourseStatusExtension);
     // generates an assoc array of courses by using a defined list of
     // its attributes
     $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension);
     // concatenates the course stats and the associated courses
     $res = DBJson::concatObjectListsSingleResult($data, $courseStatus, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert()['CS_course'], $courses, Course::getDBPrimaryKey(), $CourseExtension, $CourseStatusExtension);
     // concatenates the users and the associated course stats
     $res = DBJson::concatResultObjectLists($data, $user, User::getDBPrimaryKey(), User::getDBConvert()['U_courses'], $res, CourseStatus::getDBPrimaryKey(), $CourseStatusExtension, $UserExtension);
     if ($isResult) {
         // to reindex
         // $res = array_merge($res);
         $res = CourseStatus::decodeCourseStatus($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #22
0
 public static function ExtractAttachment($data, $singleResult = false, $FileExtension = '', $AttachmentExtension = '', $isResult = true)
 {
     // generates an assoc array of files by using a defined list of
     // its attributes
     $files = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $FileExtension);
     // generates an assoc array of attachments by using a defined list of
     // its attributes
     $attachments = DBJson::getObjectsByAttributes($data, Attachment::getDBPrimaryKey(), Attachment::getDBConvert(), $AttachmentExtension);
     // concatenates the attachments and the associated files
     $res = DBJson::concatObjectListsSingleResult($data, $attachments, Attachment::getDBPrimaryKey(), Attachment::getDBConvert()['F_file'], $files, File::getDBPrimaryKey(), $FileExtension, $AttachmentExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Attachment::decodeAttachment($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #23
0
 public function postQuery($callName, $input, $par = array())
 {
     $par = DBJson::mysql_real_escape_string($par);
     $params = array();
     extract($par, EXTR_OVERWRITE);
     $config = parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE);
     $obj = $input;
     $answer = DBRequest::request2($obj->getRequest(), $obj->getCheckSession(), $config);
     $result = Model::isOK();
     $result['content'] = array();
     $res = array();
     foreach ($answer as $query_result) {
         $obj = new Query();
         if ($query_result['errno'] != 0) {
             if (isset($query_result['errno']) && $query_result['errno'] != 0) {
                 Logger::Log('GET queryResult failed errno: ' . $query_result['errno'] . ' error: ' . $query_result['error'], LogLevel::ERROR);
             }
             if (!isset($query_result['content']) || !$query_result['content']) {
                 Logger::Log('GET queryResult failed, no content', LogLevel::ERROR);
             }
             if (isset($query_result['errno']) && $query_result['errno'] == 401) {
                 $result = Model::isRejected();
             } else {
                 $result = Model::isProblem();
             }
         } elseif (gettype($query_result['content']) == 'boolean') {
             $obj->setResponse(array());
             if (isset($query_result['affectedRows'])) {
                 $obj->setAffectedRows($query_result['affectedRows']);
             }
             if (isset($query_result['insertId'])) {
                 $obj->setInsertId($query_result['insertId']);
             }
             if (isset($query_result['errno'])) {
                 $obj->setErrno($query_result['errno']);
             }
             if (isset($query_result['numRows'])) {
                 $obj->setNumRows($query_result['numRows']);
             }
             if (isset($query_result['errno']) && $query_result['errno'] > 0) {
                 $result = Model::isProblem();
             } else {
                 $result = Model::isCreated();
             }
         } else {
             $data = array();
             if (isset($query_result['numRows']) && $query_result['numRows'] > 0) {
                 $data = $query_result['content'];
             }
             $obj->setResponse($data);
             if (isset($query_result['affectedRows'])) {
                 $obj->setAffectedRows($query_result['affectedRows']);
             }
             if (isset($query_result['insertId'])) {
                 $obj->setInsertId($query_result['insertId']);
             }
             if (isset($query_result['errno'])) {
                 $obj->setErrno($query_result['errno']);
             }
             if (isset($query_result['numRows'])) {
                 $obj->setNumRows($query_result['numRows']);
             }
             if (isset($query_result['errno']) && $query_result['errno'] > 0) {
                 $result = Model::isProblem();
             } else {
                 $result = Model::isCreated();
             }
             //$result = Model::isOK();
         }
         $res[] = $obj;
     }
     if (count($res) == 1) {
         $res = $res[0];
     }
     $result['content'] = $res;
     return $result;
 }
Beispiel #24
0
 public function get($functionName, $sqlFile, $userid, $courseid, $esid, $eid, $suid, $aid, $singleResult = false, $checkSession = true)
 {
     Logger::Log('starts GET ' . $functionName, LogLevel::DEBUG);
     // checks whether incoming data has the correct data type
     DBJson::checkInput($this->_app, $userid == '' ? true : ctype_digit($userid), $courseid == '' ? true : ctype_digit($courseid), $esid == '' ? true : ctype_digit($esid), $eid == '' ? true : ctype_digit($eid), $suid == '' ? true : ctype_digit($suid), $aid == '' ? true : ctype_digit($aid));
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('userid' => $userid, 'courseid' => $courseid, 'esid' => $esid, 'eid' => $eid, 'suid' => $suid, 'aid' => $aid), $checkSession);
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         if ($query->getNumRows() > 0) {
             $res = Attachment::ExtractAttachment($query->getResponse(), $singleResult);
             $this->_app->response->setBody(Attachment::encodeAttachment($res));
             $this->_app->response->setStatus(200);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
             $this->_app->stop();
         } else {
             $result['status'] = 404;
         }
     }
     Logger::Log('GET ' . $functionName . ' failed', LogLevel::ERROR);
     $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
     $this->_app->response->setBody(Attachment::encodeAttachment(new Attachment()));
     $this->_app->stop();
 }
Beispiel #25
0
 /**
  * Removes the component from a given course
  *
  * Called when this component receives an HTTP DELETE request to
  * /course/$courseid(/).
  *
  * @param string $courseid The id of the course.
  */
 public function deleteCourse($courseid)
 {
     $this->app->response->setStatus(201);
     Logger::Log('starts DELETE DeleteCourse', LogLevel::DEBUG);
     $header = $this->app->request->headers->all();
     $courseid = DBJson::mysql_real_escape_string($courseid);
     foreach ($this->_createCourse as $_link) {
         $result = Request::routeRequest('DELETE', '/course/' . $courseid, $header, '', $_link, 'course');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             if (isset($result['headers']['Content-Type'])) {
                 $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             Logger::Log('POST DeleteCourse failed', LogLevel::ERROR);
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->stop();
         }
     }
 }
Beispiel #26
0
 public static function ExtractSetting($data, $singleResult = false, $SettingExtension = '', $isResult = true)
 {
     // generates an assoc array of Settings by using a defined list of
     // its attributes
     $res = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert(), $SettingExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Setting::decodeSetting($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
 public static function ExtractApprovalCondition($data, $singleResult = false, $ApprovalExtension = '', $isResult = true)
 {
     // generates an assoc array of an approval condition by using a
     // defined list of its attributes
     $res = DBJson::getResultObjectsByAttributes($data, ApprovalCondition::getDBPrimaryKey(), ApprovalCondition::getDBConvert(), $ApprovalExtension);
     if ($isResult) {
         // to reindex
         $res = array_merge($res);
         $res = ApprovalCondition::decodeApprovalCondition($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
 public static function ExtractSelectedSubmission($data, $singleResult = false, $SelectedSubmissionExtension = '', $isResult = true)
 {
     // generates an assoc array of selected entry's by using a defined list of
     // its attributes
     $res = DBJson::getResultObjectsByAttributes($data, SelectedSubmission::getDBPrimaryKey(), SelectedSubmission::getDBConvert(), $SelectedSubmissionExtension);
     if ($isResult) {
         $res = SelectedSubmission::decodeSelectedSubmission($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Beispiel #29
0
 public function getSamplesInfo($callName, $input, $params = array())
 {
     $positive = function ($input) {
         $result = Model::isEmpty();
         $result['content'] = array();
         foreach ($input as $inp) {
             if ($inp->getNumRows() > 0) {
                 foreach ($inp->getResponse() as $key => $value) {
                     foreach ($value as $key2 => $value2) {
                         $result['content'][] = $value2;
                     }
                 }
                 $result['status'] = 200;
             }
         }
         return $result;
     };
     $params = DBJson::mysql_real_escape_string($params);
     return $this->_component->call($callName, $params, '', 200, $positive, array(), 'Model::isProblem', array(), 'Query');
 }
Beispiel #30
0
 public static function ExtractCourse($data, $singleResult = false, $CourseExtension = '', $SheetExtension = '', $isResult = true)
 {
     // generates an assoc array of courses by using a defined list of
     // its attributes
     $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension);
     // generates an assoc array of settings by using a defined list of
     // its attributes
     $settings = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert());
     // generates an assoc array of exercise sheets by using a defined list of
     // its attributes
     $exerciseSheets = DBJson::getObjectsByAttributes($data, ExerciseSheet::getDBPrimaryKey(), array(ExerciseSheet::getDBPrimaryKey() => ExerciseSheet::getDBConvert()[ExerciseSheet::getDBPrimaryKey()]), $SheetExtension);
     // concatenates the courses and the associated settings
     $res = DBJson::concatObjectListResult($data, $courses, Course::getDBPrimaryKey(), Course::getDBConvert()['C_settings'], $settings, Setting::getDBPrimaryKey());
     // concatenates the courses and the associated exercise sheet IDs
     $res = DBJson::concatResultObjectListAsArray($data, $res, Course::getDBPrimaryKey(), Course::getDBConvert()['C_exerciseSheets'], $exerciseSheets, ExerciseSheet::getDBPrimaryKey(), $SheetExtension, $CourseExtension);
     if ($isResult) {
         $res = Course::decodeCourse($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }