Skip to content

Commit 9339581

Browse files
committed
Adding signature + onlyoffice fix, auto template
Adding signature + onlyoffice fix, auto template
1 parent 01c316e commit 9339581

15 files changed

Lines changed: 698 additions & 424 deletions

‎app/Controller/AppController.php‎

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,11 +1098,23 @@ public function delete() {
10981098
}
10991099
if ($this->request->controller != 'custom_tables') {
11001100
if ($this->request->is('post') || $this->request->is('put')) {
1101-
$model = $this->modelClass;
1102-
$record = $this->$model->find('first',array('conditions'=>array($model.'.id'=>$id),'recursive'=>-1));
1103-
$this->_recursive_delete($this->request->data[$model]['id'],$model);
1104-
$this->redirect(array('action' => 'index','custom_table_id'=>$record[$model]['custom_table_id'],'qc_document_id'=>$record[$model]['qc_document_id']));
1105-
} else {
1101+
if($this->request->controller == 'users'){
1102+
$user = $this->User->find('first',array('conditions'=>array('User.id'=>$id)));
1103+
if($user['User']['sr_no'] == 1){
1104+
$this->Session->setFlash(__('You can not delete this user'));
1105+
}
1106+
$user = $this->User->find('count');
1107+
if($user == 1){
1108+
$this->Session->setFlash(__('You can not delete this user'));
1109+
}
1110+
$this->redirect(array('action' => 'index','custom_table_id'=>$record[$model]['custom_table_id'],'qc_document_id'=>$record[$model]['qc_document_id']));
1111+
}else{
1112+
$model = $this->modelClass;
1113+
$record = $this->$model->find('first',array('conditions'=>array($model.'.id'=>$id),'recursive'=>-1));
1114+
$this->_recursive_delete($this->request->data[$model]['id'],$model);
1115+
$this->redirect(array('action' => 'index','custom_table_id'=>$record[$model]['custom_table_id'],'qc_document_id'=>$record[$model]['qc_document_id']));
1116+
}
1117+
} else {
11061118
$model = $this->modelClass;
11071119
$this->loadModel($model);
11081120
$rec = $this->$model->find('first',array('conditions'=>array($model.'.id'=>$this->request->params['pass'][0]),'fields'=>array($model.'.id',$model.'.prepared_by')));
@@ -4129,4 +4141,81 @@ public function _write_to_file($folder = null, $file = null, $content = null){
41294141
fclose($fp);
41304142
}
41314143
}
4144+
4145+
public function addsignature($employee_id = null, $fieldid = null){
4146+
$this->layout = 'ajax';
4147+
if ($this->request->is('post') || $this->request->is('put')) {
4148+
if($this->request->data['AddSignature']['user_password']){
4149+
$this->loadModel('User');
4150+
$user = $this->User->find('first', array(
4151+
'fields'=>array(
4152+
'User.id',
4153+
'User.password',
4154+
'User.employee_id',
4155+
'Employee.id',
4156+
'Employee.signature',
4157+
),
4158+
'conditions' => array('User.status' => 1, 'User.soft_delete' => 0, 'User.publish' => 1, 'User.employee_id' => $this->request->data['AddSignature']['employee_id'])));
4159+
4160+
if($user){
4161+
if (trim($user['User']['password']) != trim(Security::hash($this->request->data['AddSignature']['user_password'], 'md5', true))) {
4162+
$response = 'Wrong password';
4163+
}else{
4164+
$img = WWW_ROOT. DS. 'img'. DS . $this->Session->read('User.company_id'). DS .'signature'. DS. $user['Employee']['id']. DS. 'sign.png';
4165+
if(file_exists($img)){
4166+
$response = 'Proceed';
4167+
}else if($user['Employee']['signature']){
4168+
$response = 'Proceed';
4169+
}else{
4170+
$response = 'Signature not available';
4171+
}
4172+
}
4173+
}else{
4174+
$response = 'Wrong user';
4175+
}
4176+
}else{
4177+
$response = 'invalid';
4178+
}
4179+
echo $response;
4180+
exit;
4181+
}else{
4182+
if($employee_id){
4183+
$this->loadModel('Employee');
4184+
$employee = $this->Employee->find(
4185+
'first',array(
4186+
'conditions'=>array('Employee.id'=>$employee_id),
4187+
'recursive'=>-1,
4188+
'fields'=>array('Employee.id','Employee.name','Employee.signature'))
4189+
);
4190+
4191+
if($employee){
4192+
$this->set('employee',$employee);
4193+
}
4194+
}
4195+
$this->set(array('fieldid'=>$fieldid,'employee_id'=>$employee_id));
4196+
$this->render('/Elements/addsignature');
4197+
}
4198+
4199+
}
4200+
4201+
public function checkpass(){
4202+
$this->autoRender = false;
4203+
if($this->request->data['AddSignature']['user_password']){
4204+
$this->loadModel('User');
4205+
$user = $this->User->find('first', array('conditions' => array('User.status' => 1, 'User.soft_delete' => 0, 'User.publish' => 1, 'User.username' => $this->Session->read('User.username'))));
4206+
4207+
if($user){
4208+
if (trim($user['User']['password']) != trim(Security::hash($this->request->data['AddSignature']['user_password'], 'md5', true))) {
4209+
$response = 'Wrong password';
4210+
}else{
4211+
$response = 'Proceed';
4212+
}
4213+
}else{
4214+
$response = 'Wrong user';
4215+
}
4216+
}else{
4217+
$response = 'wrong data';
4218+
}
4219+
return $response;
4220+
}
41324221
}

‎app/Controller/CustomTablesController.php‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ public function _add_new_table($table_name = null,$defaultfield = null,$sqld = n
384384
$this->Session->setFlash(__('Something went wrong'), 'default', array('class' => 'alert alert-danger'));
385385
$this->redirect($this->referer());
386386
}
387-
388387
// run above sql first and then add alter table commands one by one
389388
foreach ($fields as $chkd) {
390389
if($chkd['new'] == 0 && $chkd['field_name'] != $chkd['old_field_name']){
@@ -410,6 +409,9 @@ public function _add_new_table($table_name = null,$defaultfield = null,$sqld = n
410409
case 6: // datetime
411410
$type = 'datetime';
412411
break;
412+
case 7: // datetime
413+
$type = 'varchar('.$chkd['length'].')';
414+
break;
413415
default: // text
414416
$type = 'text';
415417
break;
@@ -451,6 +453,9 @@ public function _add_new_table($table_name = null,$defaultfield = null,$sqld = n
451453
default: // text
452454
$type = 'text';
453455
break;
456+
case 7: // datetime
457+
$type = 'varchar('.$chkd['length'].')';
458+
break;
454459
}
455460

456461
if($chkd['mandetory'] == 1)$m = ' NOT ';
@@ -852,6 +857,12 @@ public function _set_file($id = null,$type = null){
852857

853858
$qcpfile = WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . $type . DS . $id . DS . $file_name;
854859
$tofile = WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . 'custom_tables' . DS . $id . DS . $file_name;
860+
$tofolder = WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . 'custom_tables' . DS . $id . DS;
861+
862+
if(file_exists($tofolder)){
863+
unlink($tofolder);
864+
}
865+
855866

856867
if (file_exists($qcpfile)) {
857868
$folder = WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . 'custom_tables' . DS . $id;
@@ -1338,7 +1349,6 @@ public function recreate($id = null) {
13381349
$belongsTo[$fields['field_name']] = $fields['linked_to'];
13391350
}
13401351
}
1341-
13421352
$sqlresult = $this->_add_new_table($table_name,$defaultfield,null,$toDrop);
13431353

13441354
if(is_array($newFields)){

0 commit comments

Comments
 (0)