function add() { if (!empty($this->data)) { /** when the data of the user arrives hir already are check */ $this->User->create(); if ($this->User->save($this->data)) { /** NOTE <add directory for this user> */ if (!empty($this->data['User']['username'])) { $directory = WWW_ROOT . 'files' . DS . 'users' . DS . $this->data['User']['username'] . DS; if (!is_dir($directory)) { foreach (createDirs() as $indx => $dir_name) { if (!mkdir($directory . $dir_name . DS, 0777, true)) { die('the dir ' . $dir_name . ' could not be create'); } } } } /** NOTE <add FieldNames to Fieldatas for this user>*/ $FieldName = $this->FieldName->find('list'); $user_id = $this->User->getLastInsertID(); $user_group = $this->data['User']['group_id']; foreach ($FieldName as $id_field_name => $field_name) { $data_user['user_id'] = $user_id; $data_user['group_id'] = $user_group; $data_user['field_names_id'] = $id_field_name; $data_user['create'] = date('Y-m-d H:m:s'); $data_user['last_ip'] = $_SERVER['REMOTE_ADDR']; $dataSet[] = $data_user; } $this->FieldData->create(); if ($this->FieldData->saveAll($dataSet)) { $this->Session->setFlash(__('The field name has been saved', true)); } else { $this->Session->setFlash(__('The field name could not be saved. Please, try again.', true)); } $this->Session->setFlash(__('The user has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The user could not be saved. Please, try again.', true)); } } $groups = $this->User->Group->find('list'); /** NOTE <set => this must be replaced for compability > */ $companies = $this->Company->find('list', array('fields' => array('nom_id', 'name'))); $this->set(compact('groups', 'companies')); }
protected function upload($uploadDir, $key, $fileType, $fileInput, $isDownload = 0) { $attr = array(); $return = array(); $attr['addtime'] = dateTime(); $attr['fileKey'] = uniqid(); $attr['filePath'] = ''; $id = M('Files')->add($attr); $pic_path = $uploadDir . '/' . date('Y') . '/' . date('m') . '/' . date('d'); createDirs($pic_path); $uploadfile_path = $pic_path . '/' . $id . '_' . date("YmdHis") . '_' . uniqid() . '.' . $fileType; $isUploaded = 0; if ($isDownload) { if (file_put_contents($uploadfile_path, $fileInput)) { $isUploaded = 1; } } else { $return['size'] = $_FILES[$fileInput]['size'][$key]; if (move_uploaded_file($_FILES[$fileInput]['tmp_name'][$key], $uploadfile_path)) { $isUploaded = 1; } } if ($isUploaded) { @chmod($uploadfile_path, 0777); $return['code'] = 1; $return['path'] = str_replace($this->fileRootDir, "", $uploadfile_path); $return['fileKey'] = $attr['fileKey']; M("Files")->where("id='%d'", array($id))->save(array('filePath' => $return['path'])); } else { $return['code'] = 0; $return['msg'] = "對不起,文件上傳失敗!"; M("Files")->where("id='%d'", array($id))->save(array('status' => 0)); } return $return; }
if (file_exists($assetsLCL . arg("path"))) { $err = $ERR_FILE_EXISTS; break; } mkdir($assetsLCL . arg("path")); case "copyfiles": if (!in_array(auth_get_class(), array("admin", "supervisor", "dirprod"))) { $err = $ERR_PERMISSION; break; } if (!file_exists($assetsLCL . arg("path"))) { $err = $ERR_FILE_NOT_FOUND; break; } if (!file_exists($assetsLCL . arg("target"))) { $ret = createDirs($assetsLCL . arg("target")); if (!$ret) { $err = $ERR_FILE_PERMISSION; break; } } $ret = deleteFiles($assetsLCL . arg("target")); if (!$ret) { $err = $ERR_FILE_PERMISSION; break; } $ret = copyFiles($assetsLCL . arg("path"), $assetsLCL . arg("target")); if (!$ret) { $err = $ERR_FILE_PERMISSION; break; }
function processFile($file, $ftp) { global $ftpConfig, $runFiles; switch ($file['action']) { case 'update': case 'run': if ($file['type'] == 'directory' && $file['name'] != '') { $dirs = explode("/", $file['path'] . '/' . $file['name']); } else { $dirs = explode("/", $file['path']); $dirs = array_slice($dirs, 0, count($dirs) - 1); } if (count($dirs) > 0) { createDirs($dirs, $ftp); } if ($file['type'] == 'file') { putContents($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftpConfig->source . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftp); } chmodFile($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $file['mode'], $ftp); // Almacenamos el archivo si se debe ejecutar if ($file['action'] == 'run' && $file['type'] == 'file') { $runFiles[] = $ftpConfig->target . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name']; } break; case 'delete': if ($file['type'] == 'directory') { deleteFTPDir($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftp); } else { $ftp->delete($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name']); } break; } }
/** NOTE <CORE builtin functions>*/ function afterFilter() { # Update User last_access datetime if ($this->Auth->user()) { $this->loadModel('User'); $this->User->id = $this->Auth->user('id'); $this->User->saveField('last_access', date('Y-m-d H:i:s')); $this->User->saveField('last_user_agent', $_SERVER['HTTP_USER_AGENT']); $this->User->saveField('last_ip', $_SERVER['REMOTE_ADDR']); /**Set Counter*/ /** NOTE <add directory to an user if not exits>*/ if ($this->Auth->user('username')) { $directory = WWW_ROOT . 'files' . DS . 'users' . DS . $this->Auth->user('username') . DS; if (!is_dir($directory)) { foreach (createDirs() as $indx => $dir_name) { if (!mkdir($directory . $dir_name . DS, 0777, true)) { die('the dir ' . $dir_name . ' could not be create'); } } } else { foreach (createDirs() as $indx => $dir_name) { if (!is_dir($directory . $dir_name . DS)) { if (!mkdir($directory . $dir_name . DS, 0777, true)) { die('the dir ' . $dir_name . ' could not be create'); } } } } } //End add directory /** NOTE <add mount points for samba => setSmb('mount|umount|create','username')>*/ // $this->setSmb('mount'); } }