Upload docs draft

This commit is contained in:
2019-09-07 21:09:13 +02:00
parent 32d4917964
commit 35efcf2293
17 changed files with 1725 additions and 70 deletions

View File

@@ -129,9 +129,9 @@ class Auth extends PhpObject
//Reset pass once a day //Reset pass once a day
if(mb_substr($asEmpl['led'], 0, 10) != date('Y-m-d')) $this->resetAuthCookie($this->getUserId()); if(mb_substr($asEmpl['led'], 0, 10) != date('Y-m-d')) $this->resetAuthCookie($this->getUserId());
} }
else $this->addError('token corrompu pour le user '.$asEmpl[Db::getId(self::USER_TABLE)]); else $this->addError('corrupted token for user '.$asEmpl[Db::getId(self::USER_TABLE)]);
} }
else $this->addError('Utilisateur '.$iUserId.' inconnu'); else $this->addError('Unknown user '.$iUserId);
} }
} }

View File

@@ -13,7 +13,8 @@ class CATC extends Main
$asClasses = array( $asClasses = array(
array('name'=>'auth', 'project'=>true), array('name'=>'auth', 'project'=>true),
array('name'=>'course', 'project'=>true), array('name'=>'course', 'project'=>true),
array('name'=>'note', 'project'=>true) array('name'=>'note', 'project'=>true),
array('name'=>'doc', 'project'=>true)
); );
parent::__construct($oClassManagement, $sProcessPage, $asClasses); parent::__construct($oClassManagement, $sProcessPage, $asClasses);
@@ -38,7 +39,7 @@ class CATC extends Main
Course::WS_TABLE => array('dates'), Course::WS_TABLE => array('dates'),
Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'), Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'),
'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'), 'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
'docs' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'path'), 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') 'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
), ),
'types' => array 'types' => array
@@ -52,40 +53,15 @@ class CATC extends Main
'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')", 'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')",
'notes' => "LONGTEXT", 'notes' => "LONGTEXT",
'type' => "VARCHAR(10)", 'type' => "VARCHAR(10)",
'path' => "VARCHAR(100)" 'filename' => "VARCHAR(200)"
), ),
'constraints' => array 'constraints' => array
( (
'docs' => "UNIQUE KEY `uni_path` (`path`)" Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)"
) )
); );
} }
public function getPage()
{
//Constants
$asGlobalVars = array(
'consts' => array(
'token_sep' => Auth::TOKEN_SEP,
'error' => self::ERROR,
'success' => self::SUCCESS,
'context' => $this->asContext,
'cookie' => Auth::USER_COOKIE_PASS
),
'vars' => $this->getVars()
);
//Pages
$asPages = array('logon', 'logoff', 'template', 'workshops', 'course');
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
//Main Page
//TODO use getMainPage parent function
$sPage = $this->getPageContent('index');
$sPage = str_replace('asGlobalVars', json_encode($asGlobalVars), $sPage);
return $sPage;
}
private function getVars() { private function getVars() {
return array( return array(
'id' => $this->oAuth->getUserId(), 'id' => $this->oAuth->getUserId(),
@@ -93,22 +69,24 @@ class CATC extends Main
); );
} }
public function getMainPage($asGlobalVars = array(), $sMainPage = 'index', $asMainPageTags=array()) public function getAppMainPage()
{ {
return parent::getMainPage( return self::getMainPage(
array( array(
'consts' => array( 'consts' => array(
'token_sep' => Auth::TOKEN_SEP, 'token_sep' => Auth::TOKEN_SEP,
'error' => self::ERROR, 'error' => self::ERROR,
'success' => self::SUCCESS, 'success' => self::SUCCESS,
'context' => $this->asContext, 'context' => $this->asContext,
'cookie' => Auth::USER_COOKIE_PASS 'cookie' => Auth::USER_COOKIE_PASS,
'courses' => (new Course($this->oDb))->getCourses()
), ),
'vars' => $this->getVars() 'vars' => $this->getVars()
), ),
'index', 'index',
array( array(
'host_url' => $this->asContext['serv_name'] 'filepath_css' => self::addTimestampToFilePath('style/catc.css'),
'filepath_js_catc' => self::addTimestampToFilePath('scripts/catc.js')
) )
); );
} }
@@ -164,13 +142,20 @@ class CATC extends Main
return self::getJsonResult($bSuccess, $sError, $asData); return self::getJsonResult($bSuccess, $sError, $asData);
} }
/* /* Docs */
public function upload()
public function getDocs($iCourseId) {
$oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
$asDocList = $oDoc->getList();
return self::getJsonResult(!empty($asDocList), '', $asDocList);
}
public function uploadDoc($iCourseId)
{ {
$this->oClassManagement->incClass('uploader', true); $this->oClassManagement->incClass('uploader', true);
$oUploader = new Uploader($this->oMedia); $oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
$oUploader = new Uploader($oDoc);
return $oUploader->sBody; return $oUploader->sBody;
} }
*/
} }

View File

@@ -43,4 +43,11 @@ class Course extends PhpObject {
return $asWorkshops; return $asWorkshops;
} }
public function getCourses($iWorkshopId=0) {
$asInfo = array('select'=> array(Db::getId(self::COURSE_TABLE), 'description', 'timeslot'), 'from' => self::COURSE_TABLE);
if($iWorkshopId > 0) $asInfo['constraint'] = array(Db::getId(self::WS_TABLE) => $iWorkshopId);
return $this->oDb->selectRows($asInfo, Db::getId(self::COURSE_TABLE));
}
} }

71
inc/doc.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
class Doc extends PhpObject {
const DOC_FOLDER = 'files/';
const DOC_TABLE = 'docs';
/**
* DB
* @var Db
*/
private $oDb;
private $iDocId;
private $iUserId;
private $iCourseId;
public function __construct(Db &$oDb, $iUserId, $iCourseId)
{
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = &$oDb;
$this->setDocId(0);
$this->setUserCourseId($iUserId, $iCourseId);
}
public function setDocId($iDocId) {
$this->iDocId = $iDocId;
}
public function setUserCourseId($iUserId, $iCourseId) {
$this->iUserId = $iUserId;
$this->iCourseId = $iCourseId;
}
public function exists($sFileName) {
return file_exists(self::DOC_FOLDER.$sFileName);
}
public function add($sFileName, $sMimeType) {
$sType = '';
switch(mime_content_type(self::getFilePath($sFileName))) {
case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': $sType = 'word'; break;
case 'application/pdf': $sType = 'pdf'; break;
case 'audio/mpeg': $sType = 'audio'; break;
case 'image/gif': $sType = 'image'; break;
case 'image/jpeg': $sType = 'image'; break;
case 'image/png': $sType = 'image'; break;
}
$asData = array_merge($this->getDocKeys(), array('filename'=>$sFileName, 'type'=>$sType));
$bResult = $this->oDb->insertRow(self::DOC_TABLE, $asData);
return $bResult?'':'error_db';
}
public function delete($sFileName) {
}
public function getList() {
return $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraints'=>$this->getDocKeys()));
}
private function getDocKeys() {
return array(Db::getId(Auth::USER_TABLE) => $this->iUserId, Db::getId(Course::COURSE_TABLE) => $this->iCourseId);
}
private static function getFilePath($sFileName) {
return self::DOC_FOLDER.$sFileName;
}
}

1517
inc/uploader.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -57,6 +57,12 @@ elseif($sAction!='' && $bLoggedIn)
case 'set_note': case 'set_note':
$sResult = $oCATC->setNote($iId, $sContent); $sResult = $oCATC->setNote($iId, $sContent);
break; break;
case 'upload_doc':
$sResult = $oCATC->uploadDoc($iId);
break;
case 'get_docs':
$sResult = $oCATC->getDocs($iId);
break;
default: default:
$sResult = CATC::getJsonResult(false, CATC::NOT_FOUND); $sResult = CATC::getJsonResult(false, CATC::NOT_FOUND);
} }
@@ -74,7 +80,7 @@ elseif($sAction!='' && !$bLoggedIn)
elseif($sAction=='register') $sResult = $oCATC->register($sToken, $sNickName); elseif($sAction=='register') $sResult = $oCATC->register($sToken, $sNickName);
else $sResult = CATC::getJsonResult(false, CATC::UNAUTHORIZED); else $sResult = CATC::getJsonResult(false, CATC::UNAUTHORIZED);
} }
else $sResult = $oCATC->getPage(); else $sResult = $oCATC->getAppMainPage();
$sDebug = ob_get_clean(); $sDebug = ob_get_clean();
if(Settings::DEBUG && $sDebug!='') $oCATC->addUncaughtError($sDebug); if(Settings::DEBUG && $sDebug!='') $oCATC->addUncaughtError($sDebug);

View File

@@ -1,5 +1,8 @@
<div id="course"> <div id="course">
<div id="docs"></div> <div id="docs">
<div id="upload_file"><input id="fileupload" type="file" name="files[]" data-url="server/php/" multiple></div>
<div id="doc_list"></div>
</div>
<div id="notes_box"> <div id="notes_box">
<div id="notes_feedback"></div> <div id="notes_feedback"></div>
<div id="notes"></div> <div id="notes"></div>
@@ -7,9 +10,11 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
oCATC.pageInit = function(asHash, bFirstPage) { oCATC.pageInit = function(asHash, bFirstPage) {
self.setPageTitle('Course');
self.tmp('id_course', asHash.items[0]); self.tmp('id_course', asHash.items[0]);
//Setup layout
self.setPageTitle('Course: '+self.consts.courses[self.tmp('id_course')].description);
//Setup Quill //Setup Quill
oEditor = new Editor('#notes'); oEditor = new Editor('#notes');
oEditor.onKeyStroke = (e) => { oEditor.onKeyStroke = (e) => {
@@ -19,27 +24,58 @@ oCATC.pageInit = function(asHash, bFirstPage) {
} }
else save(); else save();
}; };
//oQuill.keyboard.addBinding({key: 'S', ctrlKey: true}, function(){saveNotes(true);});
//Load notes //Load notes
Tools.ajax( Tools.ajax(
'get_note', 'get_note',
(asData) => { (asData) => {
oEditor.setContent(asData.notes); oEditor.setContent(asData.notes);
oCATC.feedback('notice', 'Last update at '+asData.led_time+' on '+asData.led_date); noteFeedback('notice', 'Last update at '+asData.led_time+' on '+asData.led_date);
}, },
{id: self.tmp('id_course')}, {id: self.tmp('id_course')},
() => {console.log('Note not found for course ID = '+self.tmp('id_course'))} () => {console.log('Note not found for course ID = '+self.tmp('id_course'))}
); );
//oQuill.keyboard.addBinding({key: 'S', ctrlKey: true}, function(){saveNotes(true);}); //Setup File Upload
$('#fileupload')
.attr('data-url', self.getActionLink('upload_doc'))
.fileupload({
dataType: 'json',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|mov|doc|docx|pdf|mp3|wav)$/i,
formData: {id: self.tmp('id_course')},
done: function(e, asData) {
$.each(asData.result.files, function(iKey, oFile) {
var sMsg = ('error' in oFile)?oFile.error:(oFile.name+" uploaded successfully");
oCATC.feedback('notice', sMsg);
});
loadDocs();
}
});
loadDocs();
}; };
oCATC.onQuitPage = function() { oCATC.onQuitPage = function() {
return save(true); return save(true);
}; };
oCATC.onFeedback = function(sType, sMsg) function loadDocs() {
{ Tools.ajax(
'get_docs',
(asData) => {
$.each(asData, function(iKey, asDoc){
$('#doc_list').append($('<p>', {})
.appendIcon('file-'+asDoc.type)
.append(asDoc.filename));
});
},
{id: self.tmp('id_course')},
() => {console.log('No doc found for course ID = '+self.tmp('id_course'))}
);
}
function noteFeedback(sType, sMsg) {
var $Feedback = $('#notes_feedback').stop(); var $Feedback = $('#notes_feedback').stop();
if(sMsg != $Feedback.find('span').text()) { if(sMsg != $Feedback.find('span').text()) {
$Feedback.fadeOut($Feedback.is(':empty')?0:'fast', function(){ $Feedback.fadeOut($Feedback.is(':empty')?0:'fast', function(){
@@ -51,8 +87,7 @@ oCATC.onFeedback = function(sType, sMsg)
} }
}; };
function save(bForce) function save(bForce) {
{
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer); if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
var bSave = (oEditor.keystrokes % 20 == 0 || bForce); var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
@@ -64,11 +99,11 @@ function save(bForce)
var sContent = oEditor.getContent(); var sContent = oEditor.getContent();
if(oEditor.id != 0) { if(oEditor.id != 0) {
self.tmp('saving', true); self.tmp('saving', true);
oCATC.onFeedback('info', 'Saving...'); noteFeedback('info', 'Saving...');
getInfo( getInfo(
'set_note', 'set_note',
function(sDesc, asData) { function(sDesc, asData) {
oCATC.feedback('notice', 'Note saved ('+asData.led_time+')'); noteFeedback('notice', 'Note saved ('+asData.led_time+')');
self.tmp('saving', false); self.tmp('saving', false);
}, },
{ {
@@ -76,14 +111,14 @@ function save(bForce)
content: sContent content: sContent
}, },
function(sError) { function(sError) {
oCATC.feedback('error', 'Not saved! An error occured: '+sError); noteFeedback('error', 'Not saved! An error occured: '+sError);
self.tmp('saving', false); self.tmp('saving', false);
oSaveTimer = setTimeout(save, 1000); oSaveTimer = setTimeout(save, 1000);
}, },
'POST' 'POST'
); );
} }
else oCATC.feedback('error', 'No Course ID'); else noteFeedback('error', 'No Course ID');
} }
} }
else { else {
@@ -91,5 +126,4 @@ function save(bForce)
} }
return true; return true;
} }
</script> </script>

View File

@@ -3,17 +3,17 @@
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="author" content="Franzz" /> <meta name="author" content="Franzz" />
<link href="style/catc.css" rel="stylesheet" type="text/css" /> <link href="[#]filepath_css[#]" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery.min.js"></script> <script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/bootstrap.bundle.min.js"></script> <script type="text/javascript" src="scripts/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="scripts/jquery.mousewheel.min.js"></script> <script type="text/javascript" src="scripts/jquery.mods.js"></script>
<script type="text/javascript" src="scripts/quill.min.js"></script> <script type="text/javascript" src="scripts/quill.min.js"></script>
<script type="text/javascript" src="scripts/common.js"></script> <script type="text/javascript" src="scripts/common.js"></script>
<script type="text/javascript" src="scripts/catc.js"></script> <script type="text/javascript" src="[#]filepath_js_catc[#]"></script>
<link rel="icon" type="image/png" href="images/favicon.png"> <link rel="icon" type="image/png" href="images/favicon.png">
<title>CATC Notes</title> <title>CATC Notes</title>
<script type="text/javascript"> <script type="text/javascript">
var oCATC = new CATC(asGlobalVars); var oCATC = new CATC([#]GLOBAL_VARS[#]);
$(document).ready(oCATC.init); $(document).ready(oCATC.init);
</script> </script>
</head> </head>

View File

@@ -5,7 +5,7 @@
</div> </div>
<div id="menu"> <div id="menu">
<ul> <ul>
<li><a href="#workshops" class="button fal fa-home"></a></li><li><a href="#logoff" class="button fal fa-logoff"></a></li> <li><input type="text" id="dico" name="dico" /></li><li><a href="#workshops" class="button fal fa-home"></a></li><li><a href="#logoff" class="button fal fa-logoff"></a></li>
</ul> </ul>
</div> </div>
<div id="main_title"><h1></h1></div> <div id="main_title"><h1></h1></div>

View File

@@ -6,3 +6,4 @@ Prise de notes pour les cours du Collège des Arts Thérapeutiques Chinois
- [ ] View docs online: audio, video, word, pdf - [ ] View docs online: audio, video, word, pdf
- [X] Take notes on courses - [X] Take notes on courses
- [ ] Quick view of muscles / nerves schemas - [ ] Quick view of muscles / nerves schemas
- [ ] Dictionary

8
scripts/jquery.mods.js Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +0,0 @@
/*!
* jQuery Mousewheel 3.1.13
*
* Copyright 2015 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b),d=c["offsetParent"in a.fn?"offsetParent":"parent"]();return d.length||(d=a("body")),parseInt(d.css("fontSize"),10)||parseInt(c.css("fontSize"),10)||16},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});

View File

@@ -24,6 +24,14 @@ $fa-css-prefix: fa;
//Workshops //Workshops
.#{$fa-css-prefix}-previous:before { content: fa-content($fa-var-chevron-left); } .#{$fa-css-prefix}-previous:before { content: fa-content($fa-var-chevron-left); }
//Course
.#{$fa-css-prefix}-file-upload:before { content: fa-content($fa-var-file-upload); }
.#{$fa-css-prefix}-file-image:before { content: fa-content($fa-var-file-image); }
.#{$fa-css-prefix}-file-audio:before { content: fa-content($fa-var-file-audio); }
.#{$fa-css-prefix}-file-video:before { content: fa-content($fa-var-file-video); }
.#{$fa-css-prefix}-file-pdf:before { content: fa-content($fa-var-file-pdf); }
.#{$fa-css-prefix}-file-word:before { content: fa-content($fa-var-file-word); }
//Writer //Writer
.#{$fa-css-prefix}-bold:before { content: fa-content($fa-var-bold); } .#{$fa-css-prefix}-bold:before { content: fa-content($fa-var-bold); }
.#{$fa-css-prefix}-underline:before { content: fa-content($fa-var-underline); } .#{$fa-css-prefix}-underline:before { content: fa-content($fa-var-underline); }

View File

@@ -1,5 +1,25 @@
#course { #course {
#docs {
position: absolute;
top: 0;
left: 0;
width: calc(30% - 1em);
height: 100%;
#upload_file {
height: 41.35px;
}
#doc_list {
background: $gray-400;
border-radius: 0.5em;
height: calc(100% - 41.35px);
width: 100%;
overflow: auto;
}
}
#notes_box { #notes_box {
position: absolute; position: absolute;
width: 70%; width: 70%;

View File

@@ -149,6 +149,12 @@ a.button:active {
#main_title { #main_title {
margin-top: 1em; margin-top: 1em;
h1 {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
} }
#main { #main {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long