Example #1
0
 function EditRow()
 {
     global $conn, $Security, $Language;
     $sFilter = $this->KeyFilter();
     $this->CurrentFilter = $sFilter;
     $sSql = $this->SQL();
     $conn->raiseErrorFn = 'ew_ErrorFn';
     $rs = $conn->Execute($sSql);
     $conn->raiseErrorFn = '';
     if ($rs === FALSE) {
         return FALSE;
     }
     if ($rs->EOF) {
         $EditRow = FALSE;
         // Update Failed
     } else {
         // Begin transaction
         if ($this->getCurrentDetailTable() != "") {
             $conn->BeginTrans();
         }
         // Save old values
         $rsold =& $rs->fields;
         $this->LoadDbValues($rsold);
         $rsnew = array();
         // Titulo
         $this->Titulo->SetDbValueDef($rsnew, $this->Titulo->CurrentValue, NULL, $this->Titulo->ReadOnly);
         // Descripcion
         $this->Descripcion->SetDbValueDef($rsnew, $this->Descripcion->CurrentValue, NULL, $this->Descripcion->ReadOnly);
         // archivo
         if (!$this->archivo->ReadOnly && !$this->archivo->Upload->KeepFile) {
             $this->archivo->Upload->DbValue = $rsold['archivo'];
             // Get original value
             if ($this->archivo->Upload->FileName == "") {
                 $rsnew['archivo'] = NULL;
             } else {
                 $rsnew['archivo'] = $this->archivo->Upload->FileName;
             }
         }
         // estado
         $this->estado->SetDbValueDef($rsnew, $this->estado->CurrentValue, NULL, $this->estado->ReadOnly);
         if (!$this->archivo->Upload->KeepFile) {
             $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
             if (!ew_Empty($this->archivo->Upload->FileName)) {
                 $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
                 $FileCount = count($NewFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                     if ($NewFiles[$i] != "") {
                         $file = $NewFiles[$i];
                         if (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file)) {
                             if (!in_array($file, $OldFiles)) {
                                 $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file);
                                 // Get new file name
                                 if ($file1 != $file) {
                                     // Rename temp file
                                     while (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1)) {
                                         // Make sure did not clash with existing upload file
                                         $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file1, TRUE);
                                     }
                                     // Use indexed name
                                     rename(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1);
                                     $NewFiles[$i] = $file1;
                                 }
                             }
                         }
                     }
                 }
                 $this->archivo->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
                 $rsnew['archivo'] = $this->archivo->Upload->FileName;
             } else {
                 $NewFiles = array();
             }
         }
         // Call Row Updating event
         $bUpdateRow = $this->Row_Updating($rsold, $rsnew);
         if ($bUpdateRow) {
             $conn->raiseErrorFn = 'ew_ErrorFn';
             if (count($rsnew) > 0) {
                 $EditRow = $this->Update($rsnew, "", $rsold);
             } else {
                 $EditRow = TRUE;
             }
             // No field to update
             $conn->raiseErrorFn = '';
             if ($EditRow) {
                 if (!$this->archivo->Upload->KeepFile) {
                     $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
                     if (!ew_Empty($this->archivo->Upload->FileName)) {
                         $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
                         $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['archivo']);
                         $FileCount = count($NewFiles);
                         for ($i = 0; $i < $FileCount; $i++) {
                             $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                             if ($NewFiles[$i] != "") {
                                 $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                                 if (file_exists($file)) {
                                     $this->archivo->Upload->SaveToFile($this->archivo->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                     // Just replace
                                 }
                             }
                         }
                     } else {
                         $NewFiles = array();
                     }
                     $FileCount = count($OldFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         if ($OldFiles[$i] != "" && !in_array($OldFiles[$i], $NewFiles)) {
                             @unlink(ew_UploadPathEx(TRUE, $this->archivo->OldUploadPath) . $OldFiles[$i]);
                         }
                     }
                 }
             }
             // Update detail records
             if ($EditRow) {
                 $DetailTblVar = explode(",", $this->getCurrentDetailTable());
                 if (in_array("seguimiento_tramites", $DetailTblVar) && $GLOBALS["seguimiento_tramites"]->DetailEdit) {
                     if (!isset($GLOBALS["seguimiento_tramites_grid"])) {
                         $GLOBALS["seguimiento_tramites_grid"] = new cseguimiento_tramites_grid();
                     }
                     // Get detail page object
                     $EditRow = $GLOBALS["seguimiento_tramites_grid"]->GridUpdate();
                 }
             }
             // Commit/Rollback transaction
             if ($this->getCurrentDetailTable() != "") {
                 if ($EditRow) {
                     $conn->CommitTrans();
                     // Commit transaction
                 } else {
                     $conn->RollbackTrans();
                     // Rollback transaction
                 }
             }
         } else {
             if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
                 // Use the message, do nothing
             } elseif ($this->CancelMessage != "") {
                 $this->setFailureMessage($this->CancelMessage);
                 $this->CancelMessage = "";
             } else {
                 $this->setFailureMessage($Language->Phrase("UpdateCancelled"));
             }
             $EditRow = FALSE;
         }
     }
     // Call Row_Updated event
     if ($EditRow) {
         $this->Row_Updated($rsold, $rsnew);
     }
     $rs->Close();
     // archivo
     ew_CleanUploadTempPath($this->archivo, $this->archivo->Upload->Index);
     return $EditRow;
 }
 function AddRow($rsold = NULL)
 {
     global $conn, $Language, $Security;
     // Check referential integrity for master table 'tramites'
     $bValidMasterRecord = TRUE;
     $sMasterFilter = $this->SqlMasterFilter_tramites();
     if (strval($this->id_tramite->CurrentValue) != "") {
         $sMasterFilter = str_replace("@codigo@", ew_AdjustSql($this->id_tramite->CurrentValue), $sMasterFilter);
     } else {
         $bValidMasterRecord = FALSE;
     }
     if ($bValidMasterRecord) {
         $rsmaster = $GLOBALS["tramites"]->LoadRs($sMasterFilter);
         $bValidMasterRecord = $rsmaster && !$rsmaster->EOF;
         $rsmaster->Close();
     }
     if (!$bValidMasterRecord) {
         $sRelatedRecordMsg = str_replace("%t", "tramites", $Language->Phrase("RelatedRecordRequired"));
         $this->setFailureMessage($sRelatedRecordMsg);
         return FALSE;
     }
     // Load db values from rsold
     if ($rsold) {
         $this->LoadDbValues($rsold);
     }
     $rsnew = array();
     // id_tramite
     $this->id_tramite->SetDbValueDef($rsnew, $this->id_tramite->CurrentValue, 0, FALSE);
     // fecha
     $this->fecha->SetDbValueDef($rsnew, ew_CurrentDate(), ew_CurrentDate());
     $rsnew['fecha'] =& $this->fecha->DbValue;
     // hora
     $this->hora->SetDbValueDef($rsnew, ew_CurrentTime(), ew_CurrentTime());
     $rsnew['hora'] =& $this->hora->DbValue;
     // titulo
     $this->titulo->SetDbValueDef($rsnew, $this->titulo->CurrentValue, NULL, FALSE);
     // archivo
     if (!$this->archivo->Upload->KeepFile) {
         $this->archivo->Upload->DbValue = "";
         // No need to delete old file
         if ($this->archivo->Upload->FileName == "") {
             $rsnew['archivo'] = NULL;
         } else {
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         }
     }
     if (!$this->archivo->Upload->KeepFile) {
         $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
         if (!ew_Empty($this->archivo->Upload->FileName)) {
             $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
             $FileCount = count($NewFiles);
             for ($i = 0; $i < $FileCount; $i++) {
                 $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                 if ($NewFiles[$i] != "") {
                     $file = $NewFiles[$i];
                     if (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file)) {
                         if (!in_array($file, $OldFiles)) {
                             $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file);
                             // Get new file name
                             if ($file1 != $file) {
                                 // Rename temp file
                                 while (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1)) {
                                     // Make sure did not clash with existing upload file
                                     $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file1, TRUE);
                                 }
                                 // Use indexed name
                                 rename(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1);
                                 $NewFiles[$i] = $file1;
                             }
                         }
                     }
                 }
             }
             $this->archivo->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         } else {
             $NewFiles = array();
         }
     }
     // Call Row Inserting event
     $rs = $rsold == NULL ? NULL : $rsold->fields;
     $bInsertRow = $this->Row_Inserting($rs, $rsnew);
     // Check if key value entered
     if ($bInsertRow && $this->ValidateKey && strval($rsnew['id_tramite']) == "") {
         $this->setFailureMessage($Language->Phrase("InvalidKeyValue"));
         $bInsertRow = FALSE;
     }
     // Check if key value entered
     if ($bInsertRow && $this->ValidateKey && strval($rsnew['fecha']) == "") {
         $this->setFailureMessage($Language->Phrase("InvalidKeyValue"));
         $bInsertRow = FALSE;
     }
     // Check if key value entered
     if ($bInsertRow && $this->ValidateKey && strval($rsnew['hora']) == "") {
         $this->setFailureMessage($Language->Phrase("InvalidKeyValue"));
         $bInsertRow = FALSE;
     }
     // Check for duplicate key
     if ($bInsertRow && $this->ValidateKey) {
         $sFilter = $this->KeyFilter();
         $rsChk = $this->LoadRs($sFilter);
         if ($rsChk && !$rsChk->EOF) {
             $sKeyErrMsg = str_replace("%f", $sFilter, $Language->Phrase("DupKey"));
             $this->setFailureMessage($sKeyErrMsg);
             $rsChk->Close();
             $bInsertRow = FALSE;
         }
     }
     if ($bInsertRow) {
         $conn->raiseErrorFn = 'ew_ErrorFn';
         $AddRow = $this->Insert($rsnew);
         $conn->raiseErrorFn = '';
         if ($AddRow) {
             if (!$this->archivo->Upload->KeepFile) {
                 $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
                 if (!ew_Empty($this->archivo->Upload->FileName)) {
                     $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
                     $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['archivo']);
                     $FileCount = count($NewFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                         if ($NewFiles[$i] != "") {
                             $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if (file_exists($file)) {
                                 $this->archivo->Upload->SaveToFile($this->archivo->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                 // Just replace
                             }
                         }
                     }
                 } else {
                     $NewFiles = array();
                 }
                 $FileCount = count($OldFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     if ($OldFiles[$i] != "" && !in_array($OldFiles[$i], $NewFiles)) {
                         @unlink(ew_UploadPathEx(TRUE, $this->archivo->OldUploadPath) . $OldFiles[$i]);
                     }
                 }
             }
         }
     } else {
         if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
             // Use the message, do nothing
         } elseif ($this->CancelMessage != "") {
             $this->setFailureMessage($this->CancelMessage);
             $this->CancelMessage = "";
         } else {
             $this->setFailureMessage($Language->Phrase("InsertCancelled"));
         }
         $AddRow = FALSE;
     }
     // Get insert id if necessary
     if ($AddRow) {
     }
     if ($AddRow) {
         // Call Row Inserted event
         $rs = $rsold == NULL ? NULL : $rsold->fields;
         $this->Row_Inserted($rs, $rsnew);
     }
     // archivo
     ew_CleanUploadTempPath($this->archivo, $this->archivo->Upload->Index);
     return $AddRow;
 }
Example #3
0
 function UploadFile()
 {
     global $objForm;
     $this->Value = NULL;
     // Reset first
     $fldvar = $this->Index < 0 ? $this->FldVar : substr($this->FldVar, 0, 1) . $this->Index . substr($this->FldVar, 1);
     $wrkvar = "fn_" . $fldvar;
     $this->FileName = @$_POST[$wrkvar];
     // Get file name
     $wrkvar = "fa_" . $fldvar;
     $this->KeepFile = @$_POST[$wrkvar] == "1";
     // Check if keep old file
     if ($this->FileName != "" && !$this->UploadMultiple) {
         $f = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $this->FileName;
         if (file_exists($f)) {
             $this->Value = file_get_contents($f);
             $this->FileSize = filesize($f);
             $this->ContentType = ew_ContentType(substr($this->Value, 0, 11), $f);
             $sizes = @getimagesize($f);
             $this->ImageWidth = @$sizes[0];
             $this->ImageHeight = @$sizes[1];
         }
     }
     return TRUE;
     // Normal return
 }
Example #4
0
 function GetTempFile($idx = -1)
 {
     $fldvar = $this->Index < 0 ? $this->FldVar : substr($this->FldVar, 0, 1) . $this->Index . substr($this->FldVar, 1);
     if ($this->FileName != "") {
         if ($this->UploadMultiple) {
             $ar = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->FileName);
             if ($idx > -1 && $idx < count($ar)) {
                 return ew_UploadTempPath($fldvar, $this->TblVar) . EW_PATH_DELIMITER . $ar[$idx];
             } else {
                 $files = array();
                 foreach ($ar as $fn) {
                     $files[] = ew_UploadTempPath($fldvar, $this->TblVar) . EW_PATH_DELIMITER . $fn;
                 }
                 return $files;
             }
         } else {
             return ew_UploadTempPath($fldvar, $this->TblVar) . EW_PATH_DELIMITER . $this->FileName;
         }
     }
     return NULL;
 }
Example #5
0
 function EditRow()
 {
     global $Security, $Language;
     $sFilter = $this->KeyFilter();
     $sFilter = $this->ApplyUserIDFilters($sFilter);
     $conn =& $this->Connection();
     $this->CurrentFilter = $sFilter;
     $sSql = $this->SQL();
     $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"];
     $rs = $conn->Execute($sSql);
     $conn->raiseErrorFn = '';
     if ($rs === FALSE) {
         return FALSE;
     }
     if ($rs->EOF) {
         $this->setFailureMessage($Language->Phrase("NoRecord"));
         // Set no record message
         $EditRow = FALSE;
         // Update Failed
     } else {
         // Save old values
         $rsold =& $rs->fields;
         $this->LoadDbValues($rsold);
         $this->s_image->OldUploadPath = "/uploads/";
         $this->s_image->UploadPath = $this->s_image->OldUploadPath;
         $this->s_images->OldUploadPath = "/uploads/";
         $this->s_images->UploadPath = $this->s_images->OldUploadPath;
         $rsnew = array();
         // s_title
         $this->s_title->SetDbValueDef($rsnew, $this->s_title->CurrentValue, "", $this->s_title->ReadOnly);
         // s_image
         if (!$this->s_image->ReadOnly && !$this->s_image->Upload->KeepFile) {
             $this->s_image->Upload->DbValue = $rsold['s_image'];
             // Get original value
             if ($this->s_image->Upload->FileName == "") {
                 $rsnew['s_image'] = NULL;
             } else {
                 $rsnew['s_image'] = $this->s_image->Upload->FileName;
             }
         }
         // s_desc
         $this->s_desc->SetDbValueDef($rsnew, $this->s_desc->CurrentValue, "", $this->s_desc->ReadOnly);
         // s_longdesc
         $this->s_longdesc->SetDbValueDef($rsnew, $this->s_longdesc->CurrentValue, "", $this->s_longdesc->ReadOnly);
         // s_images
         if (!$this->s_images->ReadOnly && !$this->s_images->Upload->KeepFile) {
             $this->s_images->Upload->DbValue = $rsold['s_images'];
             // Get original value
             if ($this->s_images->Upload->FileName == "") {
                 $rsnew['s_images'] = NULL;
             } else {
                 $rsnew['s_images'] = $this->s_images->Upload->FileName;
             }
         }
         // s_caption
         $this->s_caption->SetDbValueDef($rsnew, $this->s_caption->CurrentValue, "", $this->s_caption->ReadOnly);
         if (!$this->s_image->Upload->KeepFile) {
             $this->s_image->UploadPath = "/uploads/";
             if (!ew_Empty($this->s_image->Upload->Value)) {
                 $rsnew['s_image'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->s_image->UploadPath), $rsnew['s_image']);
                 // Get new file name
             }
         }
         if (!$this->s_images->Upload->KeepFile) {
             $this->s_images->UploadPath = "/uploads/";
             $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->DbValue);
             if (!ew_Empty($this->s_images->Upload->FileName)) {
                 $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->FileName);
                 $FileCount = count($NewFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     $fldvar = $this->s_images->Upload->Index < 0 ? $this->s_images->FldVar : substr($this->s_images->FldVar, 0, 1) . $this->s_images->Upload->Index . substr($this->s_images->FldVar, 1);
                     if ($NewFiles[$i] != "") {
                         $file = $NewFiles[$i];
                         if (file_exists(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file)) {
                             if (!in_array($file, $OldFiles)) {
                                 $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->s_images->UploadPath), $file);
                                 // Get new file name
                                 if ($file1 != $file) {
                                     // Rename temp file
                                     while (file_exists(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file1)) {
                                         // Make sure did not clash with existing upload file
                                         $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->s_images->UploadPath), $file1, TRUE);
                                     }
                                     // Use indexed name
                                     rename(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file1);
                                     $NewFiles[$i] = $file1;
                                 }
                             }
                         }
                     }
                 }
                 $this->s_images->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
                 $rsnew['s_images'] = $this->s_images->Upload->FileName;
             } else {
                 $NewFiles = array();
             }
         }
         // Call Row Updating event
         $bUpdateRow = $this->Row_Updating($rsold, $rsnew);
         if ($bUpdateRow) {
             $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"];
             if (count($rsnew) > 0) {
                 $EditRow = $this->Update($rsnew, "", $rsold);
             } else {
                 $EditRow = TRUE;
             }
             // No field to update
             $conn->raiseErrorFn = '';
             if ($EditRow) {
                 if (!$this->s_image->Upload->KeepFile) {
                     if (!ew_Empty($this->s_image->Upload->Value)) {
                         $this->s_image->Upload->SaveToFile($this->s_image->UploadPath, $rsnew['s_image'], TRUE);
                     }
                 }
                 if (!$this->s_images->Upload->KeepFile) {
                     $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->DbValue);
                     if (!ew_Empty($this->s_images->Upload->FileName)) {
                         $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->FileName);
                         $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['s_images']);
                         $FileCount = count($NewFiles);
                         for ($i = 0; $i < $FileCount; $i++) {
                             $fldvar = $this->s_images->Upload->Index < 0 ? $this->s_images->FldVar : substr($this->s_images->FldVar, 0, 1) . $this->s_images->Upload->Index . substr($this->s_images->FldVar, 1);
                             if ($NewFiles[$i] != "") {
                                 $file = ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $NewFiles[$i];
                                 if (file_exists($file)) {
                                     $this->s_images->Upload->SaveToFile($this->s_images->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                     // Just replace
                                 }
                             }
                         }
                     } else {
                         $NewFiles = array();
                     }
                 }
             }
         } else {
             if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
                 // Use the message, do nothing
             } elseif ($this->CancelMessage != "") {
                 $this->setFailureMessage($this->CancelMessage);
                 $this->CancelMessage = "";
             } else {
                 $this->setFailureMessage($Language->Phrase("UpdateCancelled"));
             }
             $EditRow = FALSE;
         }
     }
     // Call Row_Updated event
     if ($EditRow) {
         $this->Row_Updated($rsold, $rsnew);
     }
     $rs->Close();
     // s_image
     ew_CleanUploadTempPath($this->s_image, $this->s_image->Upload->Index);
     // s_images
     ew_CleanUploadTempPath($this->s_images, $this->s_images->Upload->Index);
     return $EditRow;
 }
Example #6
0
 function ResizeAndSaveToFile($Width, $Height, $Quality, $Path, $NewFileName, $OverWrite, $idx = -1)
 {
     $bResult = FALSE;
     if (!ew_Empty($this->Value)) {
         $OldValue = $this->Value;
         $this->Resize($Width, $Height, $Quality);
         $bResult = $this->SaveToFile($Path, $NewFileName, $OverWrite);
         $this->Value = $OldValue;
     } elseif ($idx >= 0) {
         // Use file from upload temp folder
         $ar = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->FileName);
         if ($idx < count($ar)) {
             $fn = $ar[$idx];
             $fldvar = $this->Index < 0 ? $this->FldVar : substr($this->FldVar, 0, 1) . $this->Index . substr($this->FldVar, 1);
             $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $fn;
             if (file_exists($file)) {
                 $this->Value = file_get_contents($file);
                 $this->Resize($Width, $Height, $Quality);
                 $bResult = $this->SaveToFile($Path, $NewFileName, $OverWrite);
                 $this->Value = NULL;
             }
         }
     }
     return $bResult;
 }
Example #7
0
 function EditRow()
 {
     global $conn, $Security, $Language;
     $sFilter = $this->KeyFilter();
     $this->CurrentFilter = $sFilter;
     $sSql = $this->SQL();
     $conn->raiseErrorFn = 'ew_ErrorFn';
     $rs = $conn->Execute($sSql);
     $conn->raiseErrorFn = '';
     if ($rs === FALSE) {
         return FALSE;
     }
     if ($rs->EOF) {
         $EditRow = FALSE;
         // Update Failed
     } else {
         // Save old values
         $rsold =& $rs->fields;
         $this->LoadDbValues($rsold);
         $this->g_image->OldUploadPath = "/gallery";
         $this->g_image->UploadPath = $this->g_image->OldUploadPath;
         $this->gd_images->OldUploadPath = "/gallery";
         $this->gd_images->UploadPath = $this->gd_images->OldUploadPath;
         $rsnew = array();
         // g_name
         $this->g_name->SetDbValueDef($rsnew, $this->g_name->CurrentValue, "", $this->g_name->ReadOnly);
         // g_image
         if (!$this->g_image->ReadOnly && !$this->g_image->Upload->KeepFile) {
             $this->g_image->Upload->DbValue = $rs->fields('g_image');
             // Get original value
             if ($this->g_image->Upload->FileName == "") {
                 $rsnew['g_image'] = NULL;
             } else {
                 $rsnew['g_image'] = $this->g_image->Upload->FileName;
             }
         }
         // gd_images
         if (!$this->gd_images->ReadOnly && !$this->gd_images->Upload->KeepFile) {
             $this->gd_images->Upload->DbValue = $rs->fields('gd_images');
             // Get original value
             if ($this->gd_images->Upload->FileName == "") {
                 $rsnew['gd_images'] = NULL;
             } else {
                 $rsnew['gd_images'] = $this->gd_images->Upload->FileName;
             }
         }
         if (!$this->g_image->Upload->KeepFile) {
             $this->g_image->UploadPath = "/gallery";
             if (!ew_Empty($this->g_image->Upload->Value)) {
                 $rsnew['g_image'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->g_image->UploadPath), $rsnew['g_image']);
                 // Get new file name
             }
         }
         if (!$this->gd_images->Upload->KeepFile) {
             $this->gd_images->UploadPath = "/gallery";
             $OldFiles = explode(",", $this->gd_images->Upload->DbValue);
             if (!ew_Empty($this->gd_images->Upload->FileName)) {
                 $NewFiles = explode(",", $this->gd_images->Upload->FileName);
                 $FileCount = count($NewFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     $fldvar = $this->gd_images->Upload->Index < 0 ? $this->gd_images->FldVar : substr($this->gd_images->FldVar, 0, 1) . $this->gd_images->Upload->Index . substr($this->gd_images->FldVar, 1);
                     if ($NewFiles[$i] != "") {
                         $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                         if (file_exists($file)) {
                             if (!in_array($NewFiles[$i], $OldFiles)) {
                                 $NewFiles[$i] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->gd_images->UploadPath), $NewFiles[$i]);
                                 // Get new file name
                                 $file1 = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                                 if ($file1 != $file) {
                                     // Rename temp file
                                     rename($file, $file1);
                                 }
                             }
                         }
                     }
                 }
                 $this->gd_images->Upload->FileName = implode(",", $NewFiles);
                 $rsnew['gd_images'] = $this->gd_images->Upload->FileName;
             } else {
                 $NewFiles = array();
             }
         }
         // Call Row Updating event
         $bUpdateRow = $this->Row_Updating($rsold, $rsnew);
         if ($bUpdateRow) {
             $conn->raiseErrorFn = 'ew_ErrorFn';
             if (count($rsnew) > 0) {
                 $EditRow = $this->Update($rsnew, "", $rsold);
             } else {
                 $EditRow = TRUE;
             }
             // No field to update
             $conn->raiseErrorFn = '';
             if ($EditRow) {
                 if (!$this->g_image->Upload->KeepFile) {
                     if (!ew_Empty($this->g_image->Upload->Value)) {
                         $this->g_image->Upload->SaveToFile($this->g_image->UploadPath, $rsnew['g_image'], TRUE);
                     }
                 }
                 if (!$this->gd_images->Upload->KeepFile) {
                     $OldFiles = explode(",", $this->gd_images->Upload->DbValue);
                     if (!ew_Empty($this->gd_images->Upload->FileName)) {
                         $NewFiles = explode(",", $this->gd_images->Upload->FileName);
                         $NewFiles2 = explode(",", $rsnew['gd_images']);
                         $FileCount = count($NewFiles);
                         for ($i = 0; $i < $FileCount; $i++) {
                             $fldvar = $this->gd_images->Upload->Index < 0 ? $this->gd_images->FldVar : substr($this->gd_images->FldVar, 0, 1) . $this->gd_images->Upload->Index . substr($this->gd_images->FldVar, 1);
                             if ($NewFiles[$i] != "") {
                                 $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                                 if (file_exists($file)) {
                                     $this->gd_images->Upload->Value = file_get_contents($file);
                                     $this->gd_images->Upload->SaveToFile($this->gd_images->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE);
                                     // Just replace
                                 }
                             }
                         }
                     } else {
                         $NewFiles = array();
                     }
                 }
             }
         } else {
             if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
                 // Use the message, do nothing
             } elseif ($this->CancelMessage != "") {
                 $this->setFailureMessage($this->CancelMessage);
                 $this->CancelMessage = "";
             } else {
                 $this->setFailureMessage($Language->Phrase("UpdateCancelled"));
             }
             $EditRow = FALSE;
         }
     }
     // Call Row_Updated event
     if ($EditRow) {
         $this->Row_Updated($rsold, $rsnew);
     }
     $rs->Close();
     // g_image
     ew_CleanUploadTempPath($this->g_image, $this->g_image->Upload->Index);
     // gd_images
     ew_CleanUploadTempPath($this->gd_images, $this->gd_images->Upload->Index);
     return $EditRow;
 }
Example #8
0
 function AddRow($rsold = NULL)
 {
     global $Language, $Security;
     $conn =& $this->Connection();
     // Load db values from rsold
     if ($rsold) {
         $this->LoadDbValues($rsold);
         $this->s_image->OldUploadPath = "/uploads/";
         $this->s_image->UploadPath = $this->s_image->OldUploadPath;
         $this->s_images->OldUploadPath = "/uploads/";
         $this->s_images->UploadPath = $this->s_images->OldUploadPath;
     }
     $rsnew = array();
     // s_title
     $this->s_title->SetDbValueDef($rsnew, $this->s_title->CurrentValue, "", FALSE);
     // s_image
     if (!$this->s_image->Upload->KeepFile) {
         $this->s_image->Upload->DbValue = "";
         // No need to delete old file
         if ($this->s_image->Upload->FileName == "") {
             $rsnew['s_image'] = NULL;
         } else {
             $rsnew['s_image'] = $this->s_image->Upload->FileName;
         }
     }
     // s_desc
     $this->s_desc->SetDbValueDef($rsnew, $this->s_desc->CurrentValue, "", FALSE);
     // s_longdesc
     $this->s_longdesc->SetDbValueDef($rsnew, $this->s_longdesc->CurrentValue, "", FALSE);
     // s_images
     if (!$this->s_images->Upload->KeepFile) {
         $this->s_images->Upload->DbValue = "";
         // No need to delete old file
         if ($this->s_images->Upload->FileName == "") {
             $rsnew['s_images'] = NULL;
         } else {
             $rsnew['s_images'] = $this->s_images->Upload->FileName;
         }
     }
     // s_caption
     $this->s_caption->SetDbValueDef($rsnew, $this->s_caption->CurrentValue, "", FALSE);
     if (!$this->s_image->Upload->KeepFile) {
         $this->s_image->UploadPath = "/uploads/";
         if (!ew_Empty($this->s_image->Upload->Value)) {
             $rsnew['s_image'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->s_image->UploadPath), $rsnew['s_image']);
             // Get new file name
         }
     }
     if (!$this->s_images->Upload->KeepFile) {
         $this->s_images->UploadPath = "/uploads/";
         $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->DbValue);
         if (!ew_Empty($this->s_images->Upload->FileName)) {
             $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->FileName);
             $FileCount = count($NewFiles);
             for ($i = 0; $i < $FileCount; $i++) {
                 $fldvar = $this->s_images->Upload->Index < 0 ? $this->s_images->FldVar : substr($this->s_images->FldVar, 0, 1) . $this->s_images->Upload->Index . substr($this->s_images->FldVar, 1);
                 if ($NewFiles[$i] != "") {
                     $file = $NewFiles[$i];
                     if (file_exists(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file)) {
                         if (!in_array($file, $OldFiles)) {
                             $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->s_images->UploadPath), $file);
                             // Get new file name
                             if ($file1 != $file) {
                                 // Rename temp file
                                 while (file_exists(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file1)) {
                                     // Make sure did not clash with existing upload file
                                     $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->s_images->UploadPath), $file1, TRUE);
                                 }
                                 // Use indexed name
                                 rename(ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $file1);
                                 $NewFiles[$i] = $file1;
                             }
                         }
                     }
                 }
             }
             $this->s_images->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
             $rsnew['s_images'] = $this->s_images->Upload->FileName;
         } else {
             $NewFiles = array();
         }
     }
     // Call Row Inserting event
     $rs = $rsold == NULL ? NULL : $rsold->fields;
     $bInsertRow = $this->Row_Inserting($rs, $rsnew);
     if ($bInsertRow) {
         $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"];
         $AddRow = $this->Insert($rsnew);
         $conn->raiseErrorFn = '';
         if ($AddRow) {
             // Get insert id if necessary
             $this->s_id->setDbValue($conn->Insert_ID());
             $rsnew['s_id'] = $this->s_id->DbValue;
             if (!$this->s_image->Upload->KeepFile) {
                 if (!ew_Empty($this->s_image->Upload->Value)) {
                     $this->s_image->Upload->SaveToFile($this->s_image->UploadPath, $rsnew['s_image'], TRUE);
                 }
             }
             if (!$this->s_images->Upload->KeepFile) {
                 $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->DbValue);
                 if (!ew_Empty($this->s_images->Upload->FileName)) {
                     $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->s_images->Upload->FileName);
                     $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['s_images']);
                     $FileCount = count($NewFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         $fldvar = $this->s_images->Upload->Index < 0 ? $this->s_images->FldVar : substr($this->s_images->FldVar, 0, 1) . $this->s_images->Upload->Index . substr($this->s_images->FldVar, 1);
                         if ($NewFiles[$i] != "") {
                             $file = ew_UploadTempPath($fldvar, $this->s_images->TblVar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if (file_exists($file)) {
                                 $this->s_images->Upload->SaveToFile($this->s_images->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                 // Just replace
                             }
                         }
                     }
                 } else {
                     $NewFiles = array();
                 }
             }
         }
     } else {
         if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
             // Use the message, do nothing
         } elseif ($this->CancelMessage != "") {
             $this->setFailureMessage($this->CancelMessage);
             $this->CancelMessage = "";
         } else {
             $this->setFailureMessage($Language->Phrase("InsertCancelled"));
         }
         $AddRow = FALSE;
     }
     if ($AddRow) {
         // Call Row Inserted event
         $rs = $rsold == NULL ? NULL : $rsold->fields;
         $this->Row_Inserted($rs, $rsnew);
     }
     // s_image
     ew_CleanUploadTempPath($this->s_image, $this->s_image->Upload->Index);
     // s_images
     ew_CleanUploadTempPath($this->s_images, $this->s_images->Upload->Index);
     return $AddRow;
 }
Example #9
0
 function AddRow($rsold = NULL)
 {
     global $conn, $Language, $Security;
     // Load db values from rsold
     if ($rsold) {
         $this->LoadDbValues($rsold);
     }
     $rsnew = array();
     // Titulo
     $this->Titulo->SetDbValueDef($rsnew, $this->Titulo->CurrentValue, NULL, FALSE);
     // fecha
     $this->fecha->SetDbValueDef($rsnew, ew_CurrentDate(), NULL);
     $rsnew['fecha'] =& $this->fecha->DbValue;
     // archivo
     if (!$this->archivo->Upload->KeepFile) {
         $this->archivo->Upload->DbValue = "";
         // No need to delete old file
         if ($this->archivo->Upload->FileName == "") {
             $rsnew['archivo'] = NULL;
         } else {
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         }
     }
     // estado
     $this->estado->SetDbValueDef($rsnew, $this->estado->CurrentValue, NULL, FALSE);
     if (!$this->archivo->Upload->KeepFile) {
         $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
         if (!ew_Empty($this->archivo->Upload->FileName)) {
             $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
             $FileCount = count($NewFiles);
             for ($i = 0; $i < $FileCount; $i++) {
                 $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                 if ($NewFiles[$i] != "") {
                     $file = $NewFiles[$i];
                     if (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file)) {
                         if (!in_array($file, $OldFiles)) {
                             $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file);
                             // Get new file name
                             if ($file1 != $file) {
                                 // Rename temp file
                                 while (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1)) {
                                     // Make sure did not clash with existing upload file
                                     $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file1, TRUE);
                                 }
                                 // Use indexed name
                                 rename(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1);
                                 $NewFiles[$i] = $file1;
                             }
                         }
                     }
                 }
             }
             $this->archivo->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         } else {
             $NewFiles = array();
         }
     }
     // Call Row Inserting event
     $rs = $rsold == NULL ? NULL : $rsold->fields;
     $bInsertRow = $this->Row_Inserting($rs, $rsnew);
     if ($bInsertRow) {
         $conn->raiseErrorFn = 'ew_ErrorFn';
         $AddRow = $this->Insert($rsnew);
         $conn->raiseErrorFn = '';
         if ($AddRow) {
             if (!$this->archivo->Upload->KeepFile) {
                 $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
                 if (!ew_Empty($this->archivo->Upload->FileName)) {
                     $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
                     $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['archivo']);
                     $FileCount = count($NewFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                         if ($NewFiles[$i] != "") {
                             $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if (file_exists($file)) {
                                 $this->archivo->Upload->SaveToFile($this->archivo->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                 // Just replace
                             }
                         }
                     }
                 } else {
                     $NewFiles = array();
                 }
                 $FileCount = count($OldFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     if ($OldFiles[$i] != "" && !in_array($OldFiles[$i], $NewFiles)) {
                         @unlink(ew_UploadPathEx(TRUE, $this->archivo->OldUploadPath) . $OldFiles[$i]);
                     }
                 }
             }
         }
     } else {
         if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
             // Use the message, do nothing
         } elseif ($this->CancelMessage != "") {
             $this->setFailureMessage($this->CancelMessage);
             $this->CancelMessage = "";
         } else {
             $this->setFailureMessage($Language->Phrase("InsertCancelled"));
         }
         $AddRow = FALSE;
     }
     // Get insert id if necessary
     if ($AddRow) {
         $this->codigo->setDbValue($conn->Insert_ID());
         $rsnew['codigo'] = $this->codigo->DbValue;
     }
     if ($AddRow) {
         // Call Row Inserted event
         $rs = $rsold == NULL ? NULL : $rsold->fields;
         $this->Row_Inserted($rs, $rsnew);
     }
     // archivo
     ew_CleanUploadTempPath($this->archivo, $this->archivo->Upload->Index);
     return $AddRow;
 }
Example #10
0
 function AddRow($rsold = NULL)
 {
     global $conn, $Language, $Security;
     // Load db values from rsold
     if ($rsold) {
         $this->LoadDbValues($rsold);
         $this->g_image->OldUploadPath = "/gallery";
         $this->g_image->UploadPath = $this->g_image->OldUploadPath;
         $this->gd_images->OldUploadPath = "/gallery";
         $this->gd_images->UploadPath = $this->gd_images->OldUploadPath;
     }
     $rsnew = array();
     // g_name
     $this->g_name->SetDbValueDef($rsnew, $this->g_name->CurrentValue, "", FALSE);
     // g_image
     if (!$this->g_image->Upload->KeepFile) {
         if ($this->g_image->Upload->FileName == "") {
             $rsnew['g_image'] = NULL;
         } else {
             $rsnew['g_image'] = $this->g_image->Upload->FileName;
         }
     }
     // gd_images
     if (!$this->gd_images->Upload->KeepFile) {
         if ($this->gd_images->Upload->FileName == "") {
             $rsnew['gd_images'] = NULL;
         } else {
             $rsnew['gd_images'] = $this->gd_images->Upload->FileName;
         }
     }
     if (!$this->g_image->Upload->KeepFile) {
         $this->g_image->UploadPath = "/gallery";
         if (!ew_Empty($this->g_image->Upload->Value)) {
             $rsnew['g_image'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->g_image->UploadPath), $rsnew['g_image']);
             // Get new file name
         }
     }
     if (!$this->gd_images->Upload->KeepFile) {
         $this->gd_images->UploadPath = "/gallery";
         $OldFiles = explode(",", $this->gd_images->Upload->DbValue);
         if (!ew_Empty($this->gd_images->Upload->FileName)) {
             $NewFiles = explode(",", $this->gd_images->Upload->FileName);
             $FileCount = count($NewFiles);
             for ($i = 0; $i < $FileCount; $i++) {
                 $fldvar = $this->gd_images->Upload->Index < 0 ? $this->gd_images->FldVar : substr($this->gd_images->FldVar, 0, 1) . $this->gd_images->Upload->Index . substr($this->gd_images->FldVar, 1);
                 if ($NewFiles[$i] != "") {
                     $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                     if (file_exists($file)) {
                         if (!in_array($NewFiles[$i], $OldFiles)) {
                             $NewFiles[$i] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->gd_images->UploadPath), $NewFiles[$i]);
                             // Get new file name
                             $file1 = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if ($file1 != $file) {
                                 // Rename temp file
                                 rename($file, $file1);
                             }
                         }
                     }
                 }
             }
             $this->gd_images->Upload->FileName = implode(",", $NewFiles);
             $rsnew['gd_images'] = $this->gd_images->Upload->FileName;
         } else {
             $NewFiles = array();
         }
     }
     // Call Row Inserting event
     $rs = $rsold == NULL ? NULL : $rsold->fields;
     $bInsertRow = $this->Row_Inserting($rs, $rsnew);
     if ($bInsertRow) {
         $conn->raiseErrorFn = 'ew_ErrorFn';
         $AddRow = $this->Insert($rsnew);
         $conn->raiseErrorFn = '';
         if ($AddRow) {
             if (!$this->g_image->Upload->KeepFile) {
                 if (!ew_Empty($this->g_image->Upload->Value)) {
                     $this->g_image->Upload->SaveToFile($this->g_image->UploadPath, $rsnew['g_image'], TRUE);
                 }
             }
             if (!$this->gd_images->Upload->KeepFile) {
                 $OldFiles = explode(",", $this->gd_images->Upload->DbValue);
                 if (!ew_Empty($this->gd_images->Upload->FileName)) {
                     $NewFiles = explode(",", $this->gd_images->Upload->FileName);
                     $NewFiles2 = explode(",", $rsnew['gd_images']);
                     $FileCount = count($NewFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         $fldvar = $this->gd_images->Upload->Index < 0 ? $this->gd_images->FldVar : substr($this->gd_images->FldVar, 0, 1) . $this->gd_images->Upload->Index . substr($this->gd_images->FldVar, 1);
                         if ($NewFiles[$i] != "") {
                             $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if (file_exists($file)) {
                                 $this->gd_images->Upload->Value = file_get_contents($file);
                                 $this->gd_images->Upload->SaveToFile($this->gd_images->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE);
                                 // Just replace
                             }
                         }
                     }
                 } else {
                     $NewFiles = array();
                 }
             }
         }
     } else {
         if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
             // Use the message, do nothing
         } elseif ($this->CancelMessage != "") {
             $this->setFailureMessage($this->CancelMessage);
             $this->CancelMessage = "";
         } else {
             $this->setFailureMessage($Language->Phrase("InsertCancelled"));
         }
         $AddRow = FALSE;
     }
     // Get insert id if necessary
     if ($AddRow) {
         $this->gd_id->setDbValue($conn->Insert_ID());
         $rsnew['gd_id'] = $this->gd_id->DbValue;
     }
     if ($AddRow) {
         // Call Row Inserted event
         $rs = $rsold == NULL ? NULL : $rsold->fields;
         $this->Row_Inserted($rs, $rsnew);
     }
     // g_image
     ew_CleanUploadTempPath($this->g_image, $this->g_image->Upload->Index);
     // gd_images
     ew_CleanUploadTempPath($this->gd_images, $this->gd_images->Upload->Index);
     return $AddRow;
 }
Example #11
0
 function AddRow($rsold = NULL)
 {
     global $conn, $Language, $Security;
     // Begin transaction
     if ($this->getCurrentDetailTable() != "") {
         $conn->BeginTrans();
     }
     // Load db values from rsold
     if ($rsold) {
         $this->LoadDbValues($rsold);
     }
     $rsnew = array();
     // Titulo
     $this->Titulo->SetDbValueDef($rsnew, $this->Titulo->CurrentValue, NULL, FALSE);
     // Descripcion
     $this->Descripcion->SetDbValueDef($rsnew, $this->Descripcion->CurrentValue, NULL, FALSE);
     // archivo
     if (!$this->archivo->Upload->KeepFile) {
         $this->archivo->Upload->DbValue = "";
         // No need to delete old file
         if ($this->archivo->Upload->FileName == "") {
             $rsnew['archivo'] = NULL;
         } else {
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         }
     }
     // estado
     $this->estado->SetDbValueDef($rsnew, $this->estado->CurrentValue, NULL, FALSE);
     if (!$this->archivo->Upload->KeepFile) {
         $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
         if (!ew_Empty($this->archivo->Upload->FileName)) {
             $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
             $FileCount = count($NewFiles);
             for ($i = 0; $i < $FileCount; $i++) {
                 $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                 if ($NewFiles[$i] != "") {
                     $file = $NewFiles[$i];
                     if (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file)) {
                         if (!in_array($file, $OldFiles)) {
                             $file1 = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file);
                             // Get new file name
                             if ($file1 != $file) {
                                 // Rename temp file
                                 while (file_exists(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1)) {
                                     // Make sure did not clash with existing upload file
                                     $file1 = ew_UniqueFilename(ew_UploadPathEx(TRUE, $this->archivo->UploadPath), $file1, TRUE);
                                 }
                                 // Use indexed name
                                 rename(ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file, ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $file1);
                                 $NewFiles[$i] = $file1;
                             }
                         }
                     }
                 }
             }
             $this->archivo->Upload->FileName = implode(EW_MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
             $rsnew['archivo'] = $this->archivo->Upload->FileName;
         } else {
             $NewFiles = array();
         }
     }
     // Call Row Inserting event
     $rs = $rsold == NULL ? NULL : $rsold->fields;
     $bInsertRow = $this->Row_Inserting($rs, $rsnew);
     if ($bInsertRow) {
         $conn->raiseErrorFn = 'ew_ErrorFn';
         $AddRow = $this->Insert($rsnew);
         $conn->raiseErrorFn = '';
         if ($AddRow) {
             if (!$this->archivo->Upload->KeepFile) {
                 $OldFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->DbValue);
                 if (!ew_Empty($this->archivo->Upload->FileName)) {
                     $NewFiles = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $this->archivo->Upload->FileName);
                     $NewFiles2 = explode(EW_MULTIPLE_UPLOAD_SEPARATOR, $rsnew['archivo']);
                     $FileCount = count($NewFiles);
                     for ($i = 0; $i < $FileCount; $i++) {
                         $fldvar = $this->archivo->Upload->Index < 0 ? $this->archivo->FldVar : substr($this->archivo->FldVar, 0, 1) . $this->archivo->Upload->Index . substr($this->archivo->FldVar, 1);
                         if ($NewFiles[$i] != "") {
                             $file = ew_UploadTempPath($fldvar) . EW_PATH_DELIMITER . $NewFiles[$i];
                             if (file_exists($file)) {
                                 $this->archivo->Upload->SaveToFile($this->archivo->UploadPath, @$NewFiles2[$i] != "" ? $NewFiles2[$i] : $NewFiles[$i], TRUE, $i);
                                 // Just replace
                             }
                         }
                     }
                 } else {
                     $NewFiles = array();
                 }
                 $FileCount = count($OldFiles);
                 for ($i = 0; $i < $FileCount; $i++) {
                     if ($OldFiles[$i] != "" && !in_array($OldFiles[$i], $NewFiles)) {
                         @unlink(ew_UploadPathEx(TRUE, $this->archivo->OldUploadPath) . $OldFiles[$i]);
                     }
                 }
             }
         }
     } else {
         if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
             // Use the message, do nothing
         } elseif ($this->CancelMessage != "") {
             $this->setFailureMessage($this->CancelMessage);
             $this->CancelMessage = "";
         } else {
             $this->setFailureMessage($Language->Phrase("InsertCancelled"));
         }
         $AddRow = FALSE;
     }
     // Get insert id if necessary
     if ($AddRow) {
         $this->codigo->setDbValue($conn->Insert_ID());
         $rsnew['codigo'] = $this->codigo->DbValue;
     }
     // Add detail records
     if ($AddRow) {
         $DetailTblVar = explode(",", $this->getCurrentDetailTable());
         if (in_array("seguimiento_tramites", $DetailTblVar) && $GLOBALS["seguimiento_tramites"]->DetailAdd) {
             $GLOBALS["seguimiento_tramites"]->id_tramite->setSessionValue($this->codigo->CurrentValue);
             // Set master key
             if (!isset($GLOBALS["seguimiento_tramites_grid"])) {
                 $GLOBALS["seguimiento_tramites_grid"] = new cseguimiento_tramites_grid();
             }
             // Get detail page object
             $AddRow = $GLOBALS["seguimiento_tramites_grid"]->GridInsert();
             if (!$AddRow) {
                 $GLOBALS["seguimiento_tramites"]->id_tramite->setSessionValue("");
             }
             // Clear master key if insert failed
         }
     }
     // Commit/Rollback transaction
     if ($this->getCurrentDetailTable() != "") {
         if ($AddRow) {
             $conn->CommitTrans();
             // Commit transaction
         } else {
             $conn->RollbackTrans();
             // Rollback transaction
         }
     }
     if ($AddRow) {
         // Call Row Inserted event
         $rs = $rsold == NULL ? NULL : $rsold->fields;
         $this->Row_Inserted($rs, $rsnew);
     }
     // archivo
     ew_CleanUploadTempPath($this->archivo, $this->archivo->Upload->Index);
     return $AddRow;
 }