@@ -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}
0 commit comments