From c89322a1186edf25c9725300ab9a1b3e7643226e Mon Sep 17 00:00:00 2001 From: Franzz Date: Mon, 16 Sep 2019 13:47:13 +0200 Subject: [PATCH] Definitions v1 --- .gitignore | 3 +- files/db/update_v1_to_v2.sql | 11 +++++ inc/catc.php | 34 ++++++++++++---- inc/definition.php | 59 +++++++++++++++++++++++++++ index.php | 8 ++++ masks/logon.html | 2 - masks/template.html | 44 ++++++++++++++++++-- scripts/catc.js | 55 ++++++++++++++++++++++--- scripts/common.js | 79 ++++++++++++++++++++++++++++++++++++ scripts/jquery.mods.js | 3 ++ style/_bootstrap.scss | 4 ++ style/_font-awesome.scss | 4 +- style/_template.scss | 21 ++++------ style/catc.css | 6 +-- style/catc.css.map | 2 +- 15 files changed, 298 insertions(+), 37 deletions(-) create mode 100644 files/db/update_v1_to_v2.sql create mode 100644 inc/definition.php diff --git a/.gitignore b/.gitignore index 0cfa0af..5f319fa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /.externalToolBuilders/ /settings.php /files/* -!/files/.htaccess \ No newline at end of file +!/files/.htaccess +!/files/db/ \ No newline at end of file diff --git a/files/db/update_v1_to_v2.sql b/files/db/update_v1_to_v2.sql new file mode 100644 index 0000000..b33a887 --- /dev/null +++ b/files/db/update_v1_to_v2.sql @@ -0,0 +1,11 @@ +CREATE TABLE `definitions` ( +`id_definition` int(10) UNSIGNED auto_increment, +`id_user` int(10) UNSIGNED, +`title` VARCHAR(50), +`description` VARCHAR(500), +`led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`id_definition`), +UNIQUE KEY `uni_def_title` (`title`)); + +ALTER TABLE definitions ADD INDEX(`id_user`); +ALTER TABLE definitions ADD FOREIGN KEY (`id_user`) REFERENCES users(`id_user`); \ No newline at end of file diff --git a/inc/catc.php b/inc/catc.php index 1692c89..4450cdc 100644 --- a/inc/catc.php +++ b/inc/catc.php @@ -14,7 +14,8 @@ class CATC extends Main array('name'=>'auth', 'project'=>true), array('name'=>'course', 'project'=>true), array('name'=>'note', 'project'=>true), - array('name'=>'doc', 'project'=>true) + array('name'=>'doc', 'project'=>true), + array('name'=>'definition', 'project'=>true) ); parent::__construct($oClassManagement, $sProcessPage, $asClasses); @@ -35,12 +36,13 @@ class CATC extends Main ( 'tables' => array ( - Auth::USER_TABLE => array(Db::getText(Auth::USER_TABLE), 'nickname', 'pass', 'cookie'), - Course::WS_TABLE => array('dates'), - Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'), - 'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'), - Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'), - 'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description') + Auth::USER_TABLE => array(Db::getText(Auth::USER_TABLE), 'nickname', 'pass', 'cookie'), + Course::WS_TABLE => array('dates'), + Course::COURSE_TABLE => array(Db::getId('workshops'), 'description', 'timeslot'), + Note::NOTE_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'), + Definition::DEF_TABLE => array(Db::getId(Auth::USER_TABLE), 'title', 'description'), + Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'), + 'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description') ), 'types' => array ( @@ -49,6 +51,7 @@ class CATC extends Main 'pass' => "VARCHAR(256) NOT NULL", 'cookie' => "VARCHAR(255)", 'dates' => "VARCHAR(50)", + 'title' => "VARCHAR(50)", 'description' => "VARCHAR(200)", 'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')", 'notes' => "LONGTEXT", @@ -57,7 +60,8 @@ class CATC extends Main ), 'constraints' => array ( - Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)" + Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)", + Definition::DEF_TABLE => "UNIQUE KEY `uni_def_title` (`title`)" ) ); } @@ -160,4 +164,18 @@ class CATC extends Main return self::getJsonResult($bResult, ''); } + + /* Defs */ + + public function getDefs() { + $oDef = new Definition($this->oDb, $this->oAuth->getUserId()); + return self::getJsonResult(true, '', $oDef->getDefinitions()); + } + + public function setDef($iDefId, $sTitle, $sDesc) { + $bNew = ($iDefId == 0); + $oDef = new Definition($this->oDb, $this->oAuth->getUserId(), $iDefId); + $bResult = $oDef->setDefinition($sTitle, $sDesc); + return self::getJsonResult($bResult, '', array('new_def'=>$bNew, 'def'=>$oDef->getDefinition())); + } } \ No newline at end of file diff --git a/inc/definition.php b/inc/definition.php new file mode 100644 index 0000000..ae9601a --- /dev/null +++ b/inc/definition.php @@ -0,0 +1,59 @@ +oDb = &$oDb; + $this->setUserId($iUserId); + $this->setDefId($iDefId); + } + + public function setUserId($iUserId) { + $this->iUserId = $iUserId; + } + + public function setDefId($iDefId) { + $this->iDefId = $iDefId; + } + + public function getDefinitions($iDefId=0) { + $asConstraints = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId); + if($iDefId > 0) $asConstraints[Db::getId(self::DEF_TABLE)] = $iDefId; + + $asDefs = $this->oDb->selectRows(array('from'=>self::DEF_TABLE, 'constraint'=>$asConstraints), Db::getId(self::DEF_TABLE)); + return $asDefs; + } + + public function getDefinition() { + $asDef = array(); + if($this->iDefId > 0) { + $asDef = $this->getDefinitions($this->iDefId); + if(!empty($asDef)) $asDef = array_shift($asDef); + } + return $asDef; + } + + public function setDefinition($sTitle, $sDesc) { + $asInfo = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId, 'title'=>$sTitle, 'description'=>$sDesc); + if($this->iDefId == 0) { + $iDefId = $this->oDb->insertRow(self::DEF_TABLE, $asInfo); + } + else { + $iDefId = $this->oDb->updateRow(self::DEF_TABLE, $this->iDefId, $asInfo); + } + $this->setDefId($iDefId); + return ($iDefId > 0); + } +} \ No newline at end of file diff --git a/index.php b/index.php index accbe1c..989442e 100644 --- a/index.php +++ b/index.php @@ -37,6 +37,8 @@ $sNickName = isset($_REQUEST['nickname'])?$_REQUEST['nickname']:''; $iApiKey = isset($_GET['api'])?$_GET['api']:''; $sContent = isset($_POST['content'])?$_POST['content']:''; $iId = isset($_REQUEST['id'])?$_REQUEST['id']:0; +$sTitle = isset($_REQUEST['title'])?$_REQUEST['title']:''; +$sDesc = isset($_REQUEST['description'])?$_REQUEST['description']:''; //Initiate class $oCATC = new CATC($oClassManagement, __FILE__); @@ -63,6 +65,12 @@ elseif($sAction!='' && $bLoggedIn) case 'get_docs': $sResult = $oCATC->getDocs($iId); break; + case 'get_defs': + $sResult = $oCATC->getDefs(); + break; + case 'set_def': + $sResult = $oCATC->setDef($iId, $sTitle, $sDesc); + break; default: $sResult = CATC::getJsonResult(false, CATC::NOT_FOUND); } diff --git a/masks/logon.html b/masks/logon.html index c8b7668..67623c8 100644 --- a/masks/logon.html +++ b/masks/logon.html @@ -36,8 +36,6 @@