diff --git a/application/controllers/jobs/Prestudentstatus.php b/application/controllers/jobs/Prestudentstatus.php new file mode 100644 index 000000000..6040368a0 --- /dev/null +++ b/application/controllers/jobs/Prestudentstatus.php @@ -0,0 +1,127 @@ +input->is_cli_request()) + { + $cli = true; + } + else + { + $this->output->set_status_header(403, 'Jobs must be run from the CLI'); + echo "Jobs must be run from the CLI"; + exit; + } + } + + /** + * Main function index as help + * + * @return void + */ + public function index() + { + $result = "The following are the available command line interface commands\n\n"; + $result .= "php index.ci.php jobs/Studienplan CorrectStudienplan"; + + echo $result.PHP_EOL; + } + + /** + * Check all Status entries if the selected studienplan is valid for this degree programm / semester + * if the Studienplan is not valid it searches for a valid studienplan an corrects the data if there is + * an unambiguouse studienplan corresponding to this status + */ + public function correctStudienplan() + { + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + + $this->PrestudentstatusModel->addSelect('tbl_prestudentstatus.prestudent_id, + tbl_prestudentstatus.studiensemester_kurzbz, + tbl_prestudentstatus.ausbildungssemester, + tbl_prestudentstatus.status_kurzbz, + tbl_prestudent.studiengang_kz, + tbl_prestudentstatus.studienplan_id, + tbl_studienplan.orgform_kurzbz'); + $this->PrestudentstatusModel->addJoin('public.tbl_prestudent', 'prestudent_id'); + $this->PrestudentstatusModel->addJoin('lehre.tbl_studienplan', 'studienplan_id','LEFT'); + $this->PrestudentstatusModel->addJoin('lehre.tbl_studienordnung', 'studienordnung_id','LEFT'); + + $status = $this->PrestudentstatusModel->loadWhere(" + NOT EXISTS ( + SELECT 1 FROM lehre.tbl_studienplan_semester + WHERE studienplan_id=tbl_prestudentstatus.studienplan_id + AND studiensemester_kurzbz=tbl_prestudentstatus.studiensemester_kurzbz + AND semester=tbl_prestudentstatus.ausbildungssemester) + AND tbl_prestudentstatus.status_kurzbz NOT IN ('Abbrecher','Diplomand','Absolvent')"); + + $sum_overall = 0; + $sum_corrected = 0; + $sum_notcorrected = 0; + + if(isSuccess($status)) + { + if(hasData($status)) + { + foreach($status->retval as $row_status) + { + $studienplan = $this->StudienplanModel->getStudienplaeneBySemester( + $row_status->studiengang_kz, + $row_status->studiensemester_kurzbz, + $row_status->ausbildungssemester, + $row_status->orgform_kurzbz); + + if(isSuccess($studienplan) && count($studienplan->retval) == 1) + { + $this->PrestudentstatusModel->resetQuery(); + $pk_arr = array('ausbildungssemester' => $row_status->ausbildungssemester, + 'studiensemester_kurzbz' => $row_status->studiensemester_kurzbz, + 'status_kurzbz' => $row_status->status_kurzbz, + 'prestudent_id' => $row_status->prestudent_id); + + $status = $this->PrestudentstatusModel->load($pk_arr); + + if(isSuccess($status)) + { + $this->PrestudentstatusModel->update($pk_arr, + array('studienplan_id' => $studienplan->retval[0]->studienplan_id)); + $sum_corrected++; + } + } + else + { + $sum_notcorrected++; + } + + $sum_overall++; + } + } + } + else + { + show_error($status->retval); + } + echo "Corrected:".$sum_corrected."\n"; + echo "Not Corrected:".$sum_notcorrected."\n"; + echo "Overall incorrect:".$sum_overall."\n"; + } +} diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 1c2190f6d..ab5ab2768 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -4,25 +4,25 @@ class DB_Model extends FHC_Model { // Default schema used by the models const DEFAULT_SCHEMA = 'public'; - + // Default model class name postfix const MODEL_POSTFIX = '_model'; - + // Query used to get the list of columns from a table const QUERY_LIST_FIELDS = 'SELECT * FROM %s WHERE 0 = 1'; - + // Constants used to convert postgresql arrays and booleans to the php equivalent const PGSQL_ARRAY_TYPE = '_'; const PGSQL_BOOLEAN_TRUE = 't'; const PGSQL_BOOLEAN_FALSE = 'f'; const PGSQL_BOOLEAN_TYPE = 'bool'; const PGSQL_BOOLEAN_ARRAY_TYPE = '_bool'; - + protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... protected $hasSequence; // False if this table has a composite primary key that is not using a sequence // True if this table has a primary key that uses a sequence - + /** * Constructor */ @@ -30,22 +30,22 @@ class DB_Model extends FHC_Model { // Call parent constructor parent::__construct(); - + // Set properties $this->pk = $pk; $this->dbTable = $dbTable; $this->hasSequence = $hasSequence; - + // Loads DB conns and confs $this->load->database(); - + // Loads the UDF library $this->load->library('UDFLib'); } - + // ------------------------------------------------------------------------------------------ // Public methods - + /** * Insert Data into DB-Table * @@ -56,13 +56,13 @@ class DB_Model extends FHC_Model { // Check class properties if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::INSERT_RIGHT))) return $ent; - + // If this table has UDF and the validation of them is ok if (isError($validate = $this->_manageUDFs($data, $this->dbTable))) return $validate; - + // DB-INSERT if ($this->db->insert($this->dbTable, $data)) { @@ -93,7 +93,7 @@ class DB_Model extends FHC_Model return error($this->db->error(), FHC_DB_ERROR); } } - + /** * Update Data in DB-Table * @@ -106,15 +106,15 @@ class DB_Model extends FHC_Model // Check class properties if (is_null($this->pk)) return error(FHC_MODEL_ERROR, FHC_NOPK); if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::UPDATE_RIGHT))) return $ent; - + // If this table has UDF and the validation of them is ok if (isError($validate = $this->_manageUDFs($data, $this->dbTable, $id))) return $validate; - + $tmpId = $id; - + // Check for composite Primary Key, prepare the where clause if (is_array($id)) { @@ -127,9 +127,9 @@ class DB_Model extends FHC_Model { $tmpId = array($this->pk => $id); } - + $this->db->where($tmpId); - + // DB-UPDATE if ($this->db->update($this->dbTable, $data)) { @@ -140,7 +140,7 @@ class DB_Model extends FHC_Model return error($this->db->error(), FHC_DB_ERROR); } } - + /** * Delete data from DB-Table * @@ -152,12 +152,12 @@ class DB_Model extends FHC_Model // Check class properties if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); if (is_null($this->pk)) return error(FHC_MODEL_ERROR, FHC_NOPK); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::DELETE_RIGHT))) return $ent; - + $tmpId = $id; - + // Check for composite Primary Key if (is_array($id)) { @@ -170,7 +170,7 @@ class DB_Model extends FHC_Model { $tmpId = array($this->pk => $id); } - + // DB-DELETE if ($this->db->delete($this->dbTable, $tmpId)) { @@ -193,12 +193,12 @@ class DB_Model extends FHC_Model // Check class properties if (is_null($this->pk)) return error(FHC_MODEL_ERROR, FHC_NOPK); if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::SELECT_RIGHT))) return $ent; - + $tmpId = $id; - + // Check for composite Primary Key if (is_array($id)) { @@ -211,7 +211,7 @@ class DB_Model extends FHC_Model { $tmpId = array($this->pk => $id); } - + // DB-SELECT if ($result = $this->db->get_where($this->dbTable, $tmpId)) { @@ -232,10 +232,10 @@ class DB_Model extends FHC_Model { // Check class properties if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::SELECT_RIGHT))) return $ent; - + // Execute query if ($result = $this->db->get_where($this->dbTable, $where)) { @@ -246,7 +246,7 @@ class DB_Model extends FHC_Model return error($this->db->error(), FHC_DB_ERROR); } } - + /** * Load data and convert a record into a list of data from the main table, * and linked to every element, the data from the side tables @@ -263,15 +263,15 @@ class DB_Model extends FHC_Model { // Check class properties if (is_null($this->dbTable)) return error(FHC_MODEL_ERROR, FHC_NODBTABLE); - + // Checks rights if (isError($ent = $this->_isEntitled(PermissionLib::SELECT_RIGHT))) return $ent; - + // List of tables on which it will work $tables = array_merge(array($mainTable), $sideTables); // Array that will contain the number of columns of each table $tableColumnsCountArray = array(); - + // Generates the select clause based on the columns of each table $select = ''; for ($t = 0; $t < count($tables); $t++) @@ -280,7 +280,7 @@ class DB_Model extends FHC_Model $schemaAndTable = $this->getSchemaAndTable($tables[$t]); // Discard the schema, not needed in the next steps $tables[$t] = $schemaAndTable->table; - + // List of the columns of the current table // NOTE: $this->db->list_fields($tables[$t]) doesn't work if there are two tables with // the same name in two different schemas, use this workaround @@ -289,7 +289,7 @@ class DB_Model extends FHC_Model { $fields = $lstColumns->retval; } - + for ($f = 0; $f < count($fields); $f++) { // To avoid overwriting of the properties within the object returned by CI @@ -298,15 +298,15 @@ class DB_Model extends FHC_Model $select .= $tables[$t].'.'.$fields[$f]->column_name.' AS '.$tables[$t].'_'.$fields[$f]->column_name; if ($f < count($fields) - 1) $select .= ', '; } - + if ($t < count($tables) - 1) $select .= ', '; - + $tableColumnsCountArray[$t] = count($fields); } - + // Adds the select clause $this->addSelect($select); - + // Execute the query $resultDB = $this->db->get_where($this->dbTable, $where); // If everything went ok... @@ -319,7 +319,7 @@ class DB_Model extends FHC_Model // of a side table $returnArray = array(); $returnArrayCounter = 0; // Array counter - + // Iterates the array that contains data from DB for ($i = 0; $i < count($resultArray); $i++) { @@ -333,15 +333,15 @@ class DB_Model extends FHC_Model for ($f = 0; $f < count($tableColumnsCountArray); $f++) { $objTmpArray[$f] = new stdClass(); // Object that will represent a data set of a table - + foreach (array_slice($objectVars, $tableColumnsCountArrayOffset, $tableColumnsCountArray[$f]) as $key => $value) { $objTmpArray[$f]->{str_replace($tables[$f].'_', '', $key)} = $value; } - + $tableColumnsCountArrayOffset += $tableColumnsCountArray[$f]; // Increasing the offset } - + // Object that represents data of the main table $mainTableObj = $objTmpArray[0]; // Fill $returnArray with all data from mainTable, and for each element will link the data from the side tables @@ -354,7 +354,7 @@ class DB_Model extends FHC_Model { $sideTableProperty = $sideTablesAliases[$t - 1]; } - + // If the side table has data. If it was used a left join all the properties could be null // NOTE: Keep this way to be compatible with a php version older than 5.5 $tmpFilteredArray = array_filter(get_object_vars($sideTableObj)); @@ -379,7 +379,7 @@ class DB_Model extends FHC_Model } } } - + // Sets result with the standard success object that contains all the studiengang $result = success($returnArray); } @@ -387,10 +387,10 @@ class DB_Model extends FHC_Model { $result = error($resultDB); } - + return $result; } - + /** * Add a table to join with * @@ -405,12 +405,12 @@ class DB_Model extends FHC_Model { return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); } - + $this->db->join($joinTable, $cond, $type); - + return success(true); } - + /** * Add order clause * @@ -420,12 +420,12 @@ class DB_Model extends FHC_Model { // Check class properties and parameters if (is_null($field) || !in_array($type, array('ASC', 'DESC'))) return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); - + $this->db->order_by($field, $type); - + return success(true); } - + /** * Add select clause * @@ -435,12 +435,12 @@ class DB_Model extends FHC_Model { // Check class properties and parameters if (is_null($select) || $select == '') return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); - + $this->db->select($select, $escape); - + return success(true); } - + /** * Add distinct clause * @@ -450,7 +450,7 @@ class DB_Model extends FHC_Model { $this->db->distinct(); } - + /** * Add limit clause * @@ -460,7 +460,7 @@ class DB_Model extends FHC_Model { // Check class properties and parameters if (!is_numeric($start) || (is_numeric($start) && $start <= 0)) return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); - + if (is_numeric($end) && $end > $start) { $this->db->limit($start, $end); @@ -469,10 +469,10 @@ class DB_Model extends FHC_Model { $this->db->limit($start); } - + return success(true); } - + /** * Add a table in the from clause * @@ -481,20 +481,20 @@ class DB_Model extends FHC_Model public function addFrom($table, $alias = null) { $tmpTable = trim($table); - + // Check parameters if (empty($tmpTable)) return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); - + if (!empty($alias)) { $tmpTable .= ' AS '.$alias; } - + $this->db->from($tmpTable); - + return success(true); } - + /** * Add one or more fields in the group by clause * @@ -509,12 +509,12 @@ class DB_Model extends FHC_Model { return error(FHC_MODEL_ERROR, FHC_MODEL_ERROR); } - + $this->db->group_by($fields); - + return success(true); } - + /** * Reset the query builder state * @@ -524,7 +524,7 @@ class DB_Model extends FHC_Model { $this->db->reset_query(); } - + /** * This method call the method escape from class CI_DB_driver, therefore: * this method determines the data type so that it can escape only string data. @@ -555,11 +555,11 @@ class DB_Model extends FHC_Model { return false; } - + // If it is null, let it be null return $val; } - + /** * Converts from PostgreSQL array to php array * It also takes care about array of booleans @@ -568,7 +568,7 @@ class DB_Model extends FHC_Model { // At least returns an empty array $result = array(); - + // String that represents the pgsql array, better if not empty if (!empty($string)) { @@ -592,44 +592,44 @@ class DB_Model extends FHC_Model $result[] = $tmp; } } - + return $result; } - + /** * Returns an array that contains a list of columns names of this table */ public function listFields() { $listFields = array(); - + // Workaround to get metadata from this table $result = $this->db->query(sprintf(DB_Model::QUERY_LIST_FIELDS, $this->dbTable)); - + if (is_object($result)) { $listFields = $result->list_fields(); } - + return $listFields; } - + /** * Checks if this table has a field == $field */ public function fieldExists($field) { $exists = true; - + // If $field is not found in the list of fields of this table if (array_search($field, $this->listFields()) === false) { $exists = false; } - + return $exists; } - + /** * Returns all the UDF contained in this table ($dbTable) * If no UDF are present, an empty array will be returned @@ -637,9 +637,9 @@ class DB_Model extends FHC_Model public function getUDFs($id, $udfName = null) { $udfs = array(); - + $this->addSelect(UDFLib::COLUMN_NAME); // select only the column with UDF - + $result = $this->load($id); if (hasData($result)) { @@ -658,10 +658,10 @@ class DB_Model extends FHC_Model } } } - + return $udfs; } - + /** * Checks if this table has the field udf_values */ @@ -669,10 +669,10 @@ class DB_Model extends FHC_Model { return $this->fieldExists(UDFLib::COLUMN_NAME); } - + // ------------------------------------------------------------------------------------------ // Protected methods - + /** * Executes a query and converts array and boolean data types from PgSql to php * @return: boolean false on failure @@ -682,7 +682,7 @@ class DB_Model extends FHC_Model protected function execQuery($query, $parametersArray = null) { $result = null; - + // If the query is empty don't lose time if (!empty($query)) { @@ -695,7 +695,7 @@ class DB_Model extends FHC_Model { $resultDB = $this->db->query($query); } - + // If no errors occurred if ($resultDB) { @@ -706,10 +706,10 @@ class DB_Model extends FHC_Model $result = error($this->db->error(), FHC_DB_ERROR); } } - + return $result; } - + /** * Get schema and table name from the parameter * If no schema are specified it will returns the parameter as table name, @@ -725,20 +725,20 @@ class DB_Model extends FHC_Model $result = new stdClass(); $result->table = $schemaAndTable; $result->schema = DB_Model::DEFAULT_SCHEMA; - + // If a schema is specified if (($pos = strpos($schemaAndTable, '.')) !== false) { $result->schema = substr($schemaAndTable, 0, $pos); $result->table = substr($schemaAndTable, $pos + 1); } - + return $result; } - + // ------------------------------------------------------------------------------------------ // Private methods - + /** * Invalid ID * @@ -749,43 +749,36 @@ class DB_Model extends FHC_Model private function _arrayCombine($idexes, $values) { if (count($idexes) != count($values)) return null; - + return array_combine($idexes, $values); } - + /** * Checks if the caller is entitled to perform this operation with this right */ private function _isEntitled($permission) { $ent = success(true); - - // If the caller is _not_ a model _and_ tries to read data, then avoids to check permissions - // Otherwise checks always the permissions - if (($permission == PermissionLib::SELECT_RIGHT - && substr(get_called_class(), -6) == DB_Model::MODEL_POSTFIX) - || $permission != PermissionLib::SELECT_RIGHT) + + $ent = $this->isEntitled($this->dbTable, $permission, FHC_NORIGHT, FHC_MODEL_ERROR); + // If true is not returned, then an error has occurred + if (isError($ent)) { - $ent = $this->isEntitled($this->dbTable, $permission, FHC_NORIGHT, FHC_MODEL_ERROR); - // If true is not returned, then an error has occurred - if (isError($ent)) - { - // Before returning the object containing the error, reset the build query - // This is for preventing that other parts of the query will be built before of the next execution - $this->resetQuery(); - } + // Before returning the object containing the error, reset the build query + // This is for preventing that other parts of the query will be built before of the next execution + $this->resetQuery(); } - + return $ent; } - + /** * Wrapper method for UDFLib->manageUDFs */ private function _manageUDFs(&$data, $schemaAndTable, $id = null) { $manageUDFs = success(true); - + if ($this->hasUDF()) { if ($id != null) @@ -797,10 +790,10 @@ class DB_Model extends FHC_Model $manageUDFs = $this->udflib->manageUDFs($data, $this->dbTable); } } - + return $manageUDFs; } - + /** * Converts array and boolean data types from PgSql to php * NOTE: PostgreSQL php drivers returns: @@ -811,7 +804,7 @@ class DB_Model extends FHC_Model private function _toPhp($result) { $toPhp = $result; // if there is nothing to convert then return the result from DB - + // If it's an object its fields will be parsed to find booleans and arrays types if (is_object($result)) { @@ -834,7 +827,7 @@ class DB_Model extends FHC_Model array_push($toBeConverterdArray, $toBeConverted); } } - + // If there is something to convert, otherwhise don't lose time if (count($toBeConverterdArray) > 0) { @@ -850,7 +843,7 @@ class DB_Model extends FHC_Model { // Single element $toBeConverted = $toBeConverterdArray[$j]; - + // Array type if (strpos($toBeConverted->type, DB_Model::PGSQL_ARRAY_TYPE) !== false) { @@ -889,10 +882,10 @@ class DB_Model extends FHC_Model $toPhp = $result->result(); } } - + return $toPhp; } - + /** * Used in loadTree to find the main tables */ @@ -905,10 +898,10 @@ class DB_Model extends FHC_Model return $i; } } - + return false; } - + /** * Workaround of CI_DB_driver->_list_columns * CI_DB_driver->list_fields($tableName), that calls CI_DB_postgre_driver->_list_columns, @@ -920,7 +913,7 @@ class DB_Model extends FHC_Model FROM information_schema.columns WHERE LOWER(table_schema) = ? AND LOWER(table_name) = ?'; - + return $this->execQuery($query, array(strtolower($schema), strtolower($table))); } } diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index dbd556dd5..d880fc5b8 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -12,18 +12,18 @@ class FHC_Model extends CI_Model public function __construct() { parent::__construct(); - + // Load languages files $this->lang->load('fhc_model'); $this->lang->load('fhcomplete'); - + // Load return message helper $this->load->helper('message'); - + // Loads the permission library $this->load->library('PermissionLib'); } - + /** * Check if the user is entitled to get access to a source with the given access type * This is a wrapper for the same method present in the PermissionLib @@ -31,19 +31,28 @@ class FHC_Model extends CI_Model public function isEntitled($sourceName, $accessType, $languageMessageCode, $msgErrorCode) { $isEntitled = success(true); - - if ($this->permissionlib->isEntitled($sourceName, $accessType) === false) + + // If script is not called from Commandline + // or the caller is _not_ a model _and_ tries to read data, then avoids to check permissions + // Otherwise checks always the permissions + if (!is_cli() || + ($accessType == PermissionLib::SELECT_RIGHT + && substr(get_called_class(), -6) == DB_Model::MODEL_POSTFIX) + || $accessType != PermissionLib::SELECT_RIGHT) { - $retval = sprintf( - '%s -> %s:%s', - lang('fhc_'.$languageMessageCode), - $this->permissionlib->getBerechtigungKurzbz($sourceName), - $accessType - ); - - $isEntitled = error($retval, $msgErrorCode); + if ($this->permissionlib->isEntitled($sourceName, $accessType) === false) + { + $retval = sprintf( + '%s -> %s:%s', + lang('fhc_'.$languageMessageCode), + $this->permissionlib->getBerechtigungKurzbz($sourceName), + $accessType + ); + + $isEntitled = error($retval, $msgErrorCode); + } } - + return $isEntitled; } } diff --git a/application/libraries/PermissionLib.php b/application/libraries/PermissionLib.php index f418f06b2..075203c96 100644 --- a/application/libraries/PermissionLib.php +++ b/application/libraries/PermissionLib.php @@ -50,10 +50,13 @@ class PermissionLib // Loads the array of resources $this->acl = $this->ci->config->item('fhc_acl'); - - // API Caller rights initialization - self::$bb = new benutzerberechtigung(); - self::$bb->getBerechtigungen(getAuthUID()); + + if (!is_cli()) + { + // API Caller rights initialization + self::$bb = new benutzerberechtigung(); + self::$bb->getBerechtigungen(getAuthUID()); + } } /** @@ -65,14 +68,21 @@ class PermissionLib public function isEntitled($sourceName, $permissionType) { $isEntitled = false; - - // If the resource exists - if (isset($this->acl[$sourceName])) + + if(!is_cli()) { - // Checks permission - $isEntitled = $this->_isBerechtigt($this->acl[$sourceName], $permissionType); + // If the resource exists + if (isset($this->acl[$sourceName])) + { + // Checks permission + $isEntitled = $this->_isBerechtigt($this->acl[$sourceName], $permissionType); + } } - + else + { + $isEntitled = true; + } + return $isEntitled; } @@ -82,12 +92,12 @@ class PermissionLib public function getBerechtigungKurzbz($sourceName) { $returnValue = null; - + if (isset($this->acl[$sourceName])) { $returnValue = $this->acl[$sourceName]; } - + return $returnValue; } @@ -97,7 +107,7 @@ class PermissionLib private function _isBerechtigt($berechtigung_kurzbz, $art = null, $oe_kurzbz = null, $kostenstelle_id = null) { $isBerechtigt = false; - + if (!is_null($berechtigung_kurzbz)) { if (self::$bb->isBerechtigt($berechtigung_kurzbz, $oe_kurzbz, $art, $kostenstelle_id)) @@ -105,7 +115,7 @@ class PermissionLib $isBerechtigt = true; } } - + return $isBerechtigt; } } diff --git a/include/cronjob.class.php b/include/cronjob.class.php index f558807fc..7848e07dd 100644 --- a/include/cronjob.class.php +++ b/include/cronjob.class.php @@ -26,7 +26,7 @@ require_once(dirname(__FILE__).'/basis_db.class.php'); require_once(dirname(__FILE__).'/datum.class.php'); -class cronjob extends basis_db +class cronjob extends basis_db { public $new; public $result = array(); @@ -54,7 +54,7 @@ class cronjob extends basis_db public $insertamum; public $insertvon; public $variablen; - + /** * Konstruktor * @param $cronjob_id ID des Cronjobs der geladen werden soll (Default=null) @@ -62,7 +62,7 @@ class cronjob extends basis_db public function __construct($cronjob_id=null) { parent::__construct(); - + if(!is_null($cronjob_id)) $this->load($cronjob_id); } @@ -79,9 +79,9 @@ class cronjob extends basis_db $this->errormsg = 'id ist ungueltig'; return false; } - + $qry = "SELECT * FROM system.tbl_cronjob WHERE cronjob_id=".$this->db_add_param($cronjob_id, FHC_INTEGER); - + if($this->db_query($qry)) { if($row = $this->db_fetch_object()) @@ -109,13 +109,13 @@ class cronjob extends basis_db $this->variablen = $row->variablen; return true; } - else + else { $this->errormsg = 'Datensatz wurde nicht gefunden'; return false; } } - else + else { $this->errormsg = 'Fehler beim Laden der Daten'; return false; @@ -163,7 +163,7 @@ class cronjob extends basis_db $this->errormsg = ''; return true; } - + /** * Speichert den aktuellen Datensatz in die Datenbank * Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt @@ -184,7 +184,7 @@ class cronjob extends basis_db //Neuen Datensatz einfuegen $qry = 'BEGIN;INSERT INTO system.tbl_cronjob (server_kurzbz, titel, beschreibung, file, last_execute, aktiv, - running, jahr, monat, tag, wochentag, stunde, minute, standalone, reihenfolge, updateamum, updatevon, + running, jahr, monat, tag, wochentag, stunde, minute, standalone, reihenfolge, updateamum, updatevon, insertamum, insertvon, variablen) VALUES('. $this->db_add_param($this->server_kurzbz).', '. $this->db_add_param($this->titel).', '. @@ -217,7 +217,7 @@ class cronjob extends basis_db $this->errormsg = 'cronjob_id muss eine gueltige Zahl sein'; return false; } - + $qry='UPDATE system.tbl_cronjob SET '. 'server_kurzbz='.$this->db_add_param($this->server_kurzbz).', '. 'titel='.$this->db_add_param($this->titel).', '. @@ -254,14 +254,14 @@ class cronjob extends basis_db $this->db_query('COMMIT'); return true; } - else + else { $this->errormsg = 'Fehler beim Auslesen der Sequence'; $this->db_query('ROLLBACK'); return false; } } - else + else { $this->errormsg = 'Fehler beim Auslesen der Sequence'; $this->db_query('ROLLBACK'); @@ -289,18 +289,18 @@ class cronjob extends basis_db $this->errormsg = 'Id ist ungueltig'; return false; } - + $qry = "DELETE FROM system.tbl_cronjob WHERE cronjob_id=".$this->db_add_param($cronjob_id, FHC_INTEGER); - + if($this->db_query($qry)) return true; - else + else { $this->errormsg = 'Fehler beim Loeschen des Datensatzes'; return false; } } - + /** * Liefert alle Cronjobs * @param $server @@ -328,7 +328,7 @@ class cronjob extends basis_db while($row = $this->db_fetch_object($result)) { $obj = new cronjob(); - + $obj->cronjob_id = $row->cronjob_id; $obj->server_kurzbz = $row->server_kurzbz; $obj->titel = $row->titel; @@ -350,60 +350,78 @@ class cronjob extends basis_db $obj->insertamum = $row->insertamum; $obj->insertvon = $row->insertvon; $obj->variablen = $row->variablen; - + $this->result[] = $obj; } return true; } - + /** * Startet einen geladenen Cronjob * * @return true wenn ok, false im Fehlerfall */ public function execute() - { + { $return = true; if($this->standalone && $this->isJobRunning()) { $this->errormsg = 'Job kann nicht ausgefuehrt werden, da noch ein anderer Job laeuft'; return false; } - + if($this->server_kurzbz!=SERVER_NAME) { $this->errormsg = 'Fehler: Dieses Script kann nur am Server '.$this->server_kurzbz.' gestartet werden. (aktueller Server laut config: '.SERVER_NAME.')'; return false; } - + $this->running = true; if(!$this->save()) return false; - + unset($this->output); - $path = dirname($this->file); - $file = basename($this->file); - $file .= ' id='.$this->cronjob_id; + + /** + * If CI cronjobs are used, the parameters needs to be handled separately otherwise the + * paramters are recognized as part of the original path if they contain slashes + * + * /var/www/index.ci.php jobs/foo method + */ + if(mb_strpos($this->file,' ') !== false) + { + $path = dirname(mb_substr($this->file,0, mb_strpos($this->file,' '))); + $file = basename(mb_substr($this->file,0, mb_strpos($this->file,' '))); + $parameter = mb_substr($this->file, mb_strpos($this->file,' ')); + } + else + { + $path = dirname($this->file); + $file = basename($this->file); + $parameter = ' id='.$this->cronjob_id; + } + + $file .= $parameter; if(chdir($path)) { exec("php $file", $this->output); //echo "Execute: php $file"; - $this->last_execute = date('Y-m-d H:i:s'); + $this->last_execute = date('Y-m-d H:i:s'); } - else + else { $this->errormsg = 'Fehler: Falscher Verzeichnisname'; $return = false; } - + $this->running = false; - + if(!$this->save()) return false; - + return $return; } - + /** * Startet einen geladenen Cronjob mit Initialisierungsparameter * Der Job setzt dann die Standardwerte fuer die Variablen @@ -411,9 +429,9 @@ class cronjob extends basis_db * @return true wenn ok, false im Fehlerfall */ public function init() - { + { $return = true; - + unset($this->output); $path = dirname($this->file); $file = basename($this->file); @@ -425,13 +443,13 @@ class cronjob extends basis_db //echo "Execute: php $file"; return true; } - else + else { $this->errormsg = 'Fehler: Falscher Verzeichnisname'; return false; } } - + /** * Prueft ob zur Zeit ein Cronjob laeuft * @@ -440,23 +458,23 @@ class cronjob extends basis_db public function isJobRunning() { $qry = 'SELECT count(*) as anzahl FROM system.tbl_cronjob WHERE running=true'; - + if($result = $this->db_query($qry)) { if($row = $this->db_fetch_object($result)) { if($row->anzahl>0) return true; - else + else return false; } - else + else { $this->errormsg = 'Fehler beim Ermitteln der Daten'; return false; } } - else + else { $this->errormsg = 'Fehler beim Ermitteln der Daten'; return false; @@ -479,7 +497,7 @@ class cronjob extends basis_db else return false; } - + /** * Prueft, ob der Wert ein Fixdatum ist * @@ -492,10 +510,10 @@ class cronjob extends basis_db return false; if($this->parseSchrittweite($value)) return false; - + return true; } - + /** * Liefert die naechste Ausfuehrungszeit des aktuell geladenen Cronjobs * @@ -512,7 +530,7 @@ class cronjob extends basis_db $stunde = date('H', $last_execute); $stunde_last = date('H', $last_execute); $minute = date('i', $last_execute); - + // wenn ein wochentag gewaehlt wird, dann wird jahr, monat und tag // nicht beruecksichtigt if($this->wochentag!='') @@ -522,14 +540,14 @@ class cronjob extends basis_db $monat = date('m',$stamp); $tag = date('d',$stamp); } - else + else { //jahr if(!$jahr_schritt = $this->parseSchrittweite($this->jahr)) $jahr = ($this->jahr!=''?$this->jahr:$jahr); - else + else $jahr+= $jahr_schritt; - + //monat if(!$monat_schritt = $this->parseSchrittweite($this->monat)) { @@ -540,13 +558,13 @@ class cronjob extends basis_db $jahr++; } } - + $monat = ($this->monat!=''?$this->monat:$monat); - + } - else + else $monat+= $monat_schritt; - + //tag if(!$tag_schritt = $this->parseSchrittweite($this->tag)) { @@ -563,10 +581,10 @@ class cronjob extends basis_db } $tag = ($this->tag!=''?$this->tag:$tag); } - else + else $tag+= $tag_schritt; } - + //Stunde if(!$stunde_schritt = $this->parseSchrittweite($this->stunde)) { @@ -587,9 +605,9 @@ class cronjob extends basis_db } $stunde = ($this->stunde!=''?$this->stunde:$stunde); } - else + else $stunde+= $stunde_schritt; - + //Minute if(!$minute_schritt = $this->parseSchrittweite($this->minute)) { @@ -617,17 +635,17 @@ class cronjob extends basis_db } $minute = ($this->minute!=''?$this->minute:$minute); } - else + else $minute+= $minute_schritt; $next = mktime($stunde, $minute, 0, $monat, $tag, $jahr); - + //Cronjobs die nicht mehr ausgefuehrt werden (Datum vor der letzten Ausfuehrung) if($next<$last_execute) $next=false; return $next; } - + /** * Parst die Cronjob ID aus den Kommandozeilenparametern * @@ -642,10 +660,10 @@ class cronjob extends basis_db return substr($row,strlen('id=')); } } - + return false; } - + /** * Prueft ob der Script-Aufruf ein Inistialisierungsaufruf ist * @@ -660,7 +678,7 @@ class cronjob extends basis_db return true; } } - + return false; } } diff --git a/system/checkStudenten.php b/system/checkStudenten.php index ad1c09f93..f093a1841 100644 --- a/system/checkStudenten.php +++ b/system/checkStudenten.php @@ -149,7 +149,12 @@ WHERE benutzer.aktiv = true AND prestudentstatus.status_kurzbz='Student' AND studiengang.studiengang_kz < 10000 - AND prestudentstatus.studiensemester_kurzbz = ".$db->db_add_param($aktSem); + AND prestudentstatus.studiensemester_kurzbz = ".$db->db_add_param($aktSem)." + AND NOT EXISTS( + SELECT 1 FROM lehre.tbl_studienplan JOIN lehre.tbl_studienordnung USING(studienordnung_id) + WHERE + tbl_studienordnung.studiengang_kz = prestudent.studiengang_kz + AND tbl_studienplan.orgform_kurzbz = prestudentstatus.orgform_kurzbz)"; if ($studiengang_kz != '') $qry .= " AND prestudent.studiengang_kz=".$db->db_add_param($studiengang_kz, FHC_INTEGER); @@ -239,7 +244,7 @@ FROM WHERE status.studiensemester_kurzbz = ".$db->db_add_param($aktSem)." AND lv.studiensemester_kurzbz = ".$db->db_add_param($aktSem)." - AND status.status_kurzbz NOT IN ('Interessent','Bewerber') + AND status.status_kurzbz NOT IN ('Interessent','Bewerber','Aufgenommener','Wartender','Abgewiesener') AND get_rolle_prestudent (prestudent_id, ".$db->db_add_param($aktSem).")='Student'"; if ($studiengang_kz != '') diff --git a/system/mlists/mlists_generate.php b/system/mlists/mlists_generate.php index 8205b96b3..e4b2d4de9 100644 --- a/system/mlists/mlists_generate.php +++ b/system/mlists/mlists_generate.php @@ -76,21 +76,21 @@ $error_msg=''; $qry = "UPDATE public.tbl_gruppe SET generiert=true WHERE UPPER(gruppe_kurzbz)=UPPER('".addslashes($gruppe)."')"; $db->db_query($qry); } - + /** * Löscht alle BenutzerInnen aus NICHT-generierten Verteilern im Studiengang 0 (Erhalter), deren Account vor mehr als 3 Wochen deaktiviert wurde */ - + $qry_delete = " DELETE FROM public.tbl_benutzergruppe WHERE tbl_benutzergruppe.studiensemester_kurzbz IS NULL AND gruppe_kurzbz IN (SELECT gruppe_kurzbz FROM public.tbl_gruppe WHERE generiert=false AND studiengang_kz=0) AND uid IN (SELECT uid FROM public.tbl_benutzer WHERE aktiv=false AND updateaktivamdb_query($qry_delete))) $error_msg .= $db->db_last_error().$qry_delete.'

'; - + echo $db->db_affected_rows($result).' inaktive BenutzerInnen wurden aus statischen Verteilern gelöscht

'; - + /** * Einfache Verteiler, deren Erstellung ohne Schleifen-Logik moeglich ist, werden ueber dieses Array erstellt * Benoetigt werden die 3 Attribute: @@ -190,7 +190,8 @@ $error_msg=''; JOIN public.tbl_benutzer ON(uid=mitarbeiter_uid) WHERE fixangestellt AND aktiv - AND mitarbeiter_uid NOT LIKE '\\\\_%'"; + AND mitarbeiter_uid NOT LIKE '\\\\_%' + AND NOT EXISTS(SELECT 1 FROM public.tbl_benutzerfunktion WHERE funktion_kurzbz='hilfskraft' AND uid=mitarbeiter_uid AND (datum_bis>=now() or datum_bis is null))"; //Alle aktiven MitarbeiterInnen mit Attribut fixangestellt=true und lektor=true $verteilerArray['tw_fix_lkt']['bezeichnung'] = 'Alle fixangestellten LektorInnen'; $verteilerArray['tw_fix_lkt']['beschreibung'] = 'Alle fixangestellten LektorInnen an der FH Technikum Wien';