From 9ca119111e93d8450db586d0d5933c9a229962bf Mon Sep 17 00:00:00 2001 From: Franzz Date: Sun, 8 Sep 2019 12:51:52 +0200 Subject: [PATCH] Add delete button on docs --- inc/catc.php | 11 +++++++++-- inc/doc.php | 21 ++++++++++++++++----- index.php | 3 +++ masks/course.html | 30 ++++++++++++++++++++++++------ scripts/catc.js | 4 ++++ style/_bootstrap.scss | 14 ++++++++++++++ style/_font-awesome.scss | 8 +++++--- style/_page_course.scss | 20 ++++---------------- style/_template.scss | 8 ++++++++ style/catc.css | 6 +++--- style/catc.css.map | 2 +- style/scss.bat | 2 +- 12 files changed, 92 insertions(+), 37 deletions(-) diff --git a/inc/catc.php b/inc/catc.php index 936b3fa..78bc4eb 100644 --- a/inc/catc.php +++ b/inc/catc.php @@ -150,12 +150,19 @@ class CATC extends Main return self::getJsonResult(!empty($asDocList), '', $asDocList); } - public function uploadDoc($iCourseId) - { + public function uploadDoc($iCourseId) { $this->oClassManagement->incClass('uploader', true); $oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId); $oUploader = new Uploader($oDoc); return $oUploader->sBody; } + + public function deleteDoc($iDocId) { + $oDoc = new Doc($this->oDb); + $oDoc->setDocId($iDocId); + $bResult = $oDoc->delete(); + + return self::getJsonResult($bResult, ''); + } } \ No newline at end of file diff --git a/inc/doc.php b/inc/doc.php index 2005db6..790ddb9 100644 --- a/inc/doc.php +++ b/inc/doc.php @@ -14,7 +14,7 @@ class Doc extends PhpObject { private $iUserId; private $iCourseId; - public function __construct(Db &$oDb, $iUserId, $iCourseId) + public function __construct(Db &$oDb, $iUserId=0, $iCourseId=0) { parent::__construct(__CLASS__, Settings::DEBUG); $this->oDb = &$oDb; @@ -53,13 +53,24 @@ class Doc extends PhpObject { return $bResult?'':'error_db'; } - public function delete($sFileName) { + public function delete() { + if($this->iDocId > 0) { + $asDoc = $this->getDoc(); + $bResult = $this->oDb->deleteRow(self::DOC_TABLE, $this->iDocId); + if($bResult) $bResult = unlink($asDoc['filepath']); + } + return $bResult; } - public function getList() { - $this->oDb->setTrace(true); - $asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$this->getDocKeys())); + public function getDoc() { + $asDocList = $this->getList(array(Db::getId(self::DOC_TABLE) => $this->iDocId)); + return array_shift($asDocList); + } + + public function getList($asConstraint=array()) { + $asKeys = empty($asConstraint)?$this->getDocKeys():$asConstraint; + $asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$asKeys)); foreach($asDocs as &$asDoc) $asDoc['filepath'] = self::getFilePath($asDoc['filename']); return $asDocs; diff --git a/index.php b/index.php index 48a5aaf..3f91cd4 100644 --- a/index.php +++ b/index.php @@ -60,6 +60,9 @@ elseif($sAction!='' && $bLoggedIn) case 'upload_doc': $sResult = $oCATC->uploadDoc($iId); break; + case 'delete_doc': + $sResult = $oCATC->deleteDoc($iId); + break; case 'get_docs': $sResult = $oCATC->getDocs($iId); break; diff --git a/masks/course.html b/masks/course.html index 79ec7e2..c7d0dc3 100644 --- a/masks/course.html +++ b/masks/course.html @@ -8,6 +8,12 @@
+
+
+ + +
+