/** * Rename the folder for the multiple uploaded files/images on insert * Only for PRO version * @param object tNG transaction object * @param string reference for the key in session for the rename rule * @return mix null or error object * @access private */ function Trigger_MultipleUploadRename(&$tNG, $uploadObj) { $reference = $uploadObj->reference; $ret = null; if (!isset($_SESSION['tng_upload'][$reference]) || count($_SESSION['tng_upload'][$reference]) == 0) { return $ret; } $pk = $tNG->getPrimaryKeyValue(); // make the rename on insert if ($tNG->transactionType == '_insert') { $hash = $_SESSION['tng_upload'][$reference]['properties']; if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) { $hashFile = $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx]; } else { $hashFile = $_SESSION['tng_upload'][$reference]['files'][1]; } if (isset($hash['pkRule']) && isset($hashFile['pk']) && isset($hash['folderRule'])) { $folderExistent = str_replace('{' . $hash['pkRule'] . '}', $hashFile['pk'], $hash['folderRule']); if (!file_exists($folderExistent)) { if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) { $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null; } else { $_SESSION['tng_upload'][$reference]['files'][1] = null; } return $ret; } $arr = explode('/', $folderExistent); if (substr($folderExistent, -1, 1) == '/' || substr($folderExistent, -1, 1) == '\\') { array_pop($arr); } $folderExistent = array_pop($arr); $folder = str_replace('{' . $hash['pkRule'] . '}', $pk, $hash['folderRule']); $arr = explode('/', $folder); if (substr($folder, -1, 1) == '/' || substr($folder, -1, 1) == '\\') { array_pop($arr); } $new = array_pop($arr); $f = implode('/', $arr) . '/'; $fld = new KT_folder(); $fld->renameFolder($f, $folderExistent, $new); if ($fld->hasError()) { $err = $fld->getError(); return new tNG_error("%s", array($err[0]), array($err[1])); } else { if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) { $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null; } else { $_SESSION['tng_upload'][$reference]['files'][1] = null; } } } } // cleanup session on update; if ($tNG->transactionType == '_update') { if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) { $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null; } else { $_SESSION['tng_upload'][$reference]['files'][1] = null; } } return $ret; }