Esempio n. 1
0
 public function addField(FlexiTableFieldObject $oField)
 {
     if ($this->existsField($oField->getName())) {
         throw new Exception("Field already exists: " . $oField->getName());
     }
     $this->addChild($oField, "field");
 }
Esempio n. 2
0
 /**
  * upload a field
  * @param FlexiTableFieldObject $oField
  * @param array $oStore
  * @param array $oRow (new form row)
  * @param array $oCurrentRow  (old row)
  */
 public function doUploadField(FlexiTableFieldObject $oField, &$oStore, &$oForm, $oCurrentRow)
 {
     $sName = $oField->getName();
     $sSavePath = is_null($oField->savepath) ? FlexiFileUtil::getFullUploadPath("media/libraries") : $oField->savepath;
     //relative path is to cut out prefix of path before saving to field
     $sFullRelativeBasePath = empty($oField->savepath) ? "" : realpath($oField->savepath);
     //if multiple file
     //var_dump($oField->type);
     if ($oField->type == "multiimage-text") {
         $aCurrentFile = array();
         if (!empty($oCurrentRow[$sName])) {
             $aCurrentFile = explode($oField->uploadseparator, $oCurrentRow[$sName]);
         }
         $aResultFile = array();
         //var_dump($oForm);
         for ($c = 1; $c <= $oField->uploadcount; $c++) {
             if (isset($oForm[$sName . "_" . $c])) {
                 $sNewFile = "media." . FlexiStringUtil::createRandomAlphaNumeric() . "_" . time();
                 $aStatus = FlexiFileUtil::storeUploadFile($oForm[$sName . "_" . $c], $sSavePath, $sNewFile . ".");
                 $this->onGetUploadFileName($sSaveDir, $sNewFile);
                 if ($aStatus["status"]) {
                     //replace photo if already exists
                     if (!empty($aCurrentFile[$c - 1])) {
                         unlink(FlexiFileUtil::getFullPathFrom($aCurrentFile[$c - 1], $sFullRelativeBasePath));
                     }
                     if ($oField->isUploadImage() && !empty($oField->maxwidth) || !empty($oField->maxheight)) {
                         FlexiImageUtil::imageResize($oField->maxwidth, $oField->maxheight, $aStatus["path"]);
                     }
                     //if savepath not declared, full path from root is saved
                     //  if declared, only save filename
                     //  "" => use base root path
                     //resize image based on max width, height
                     //FlexiImageUtil::imageResize(345, 287, $aStatus["path"]);
                     $aResultFile[$c - 1] = FlexiFileUtil::getRelativePathFrom($aStatus["path"], $sFullRelativeBasePath);
                 } else {
                     //No file
                     $aResultFile[$c - 1] = $aCurrentFile[$c - 1];
                 }
             }
         }
         //for each file
         $oStore[$sName] = implode($oField->uploadseparator, $aResultFile);
     } else {
         //single file upload
         if (!isset($oForm[$sName])) {
             return;
         }
         //isupload form, presume
         if (is_array($oForm[$sName])) {
             $sNewFile = "media." . FlexiStringUtil::createRandomAlphaNumeric() . "_" . time();
             //var_dump($oRow[$sName]);
             $aStatus = FlexiFileUtil::storeUploadFile($oForm[$sName], $sSavePath, $sNewFile . ".");
             $this->onGetUploadFileName($sSaveDir, $sNewFile);
             if ($aStatus["status"]) {
                 //replace photo if already exists
                 if (!empty($oCurrentRow[$sName])) {
                     $sOldPath = FlexiFileUtil::getRelativePathFrom($oCurrentRow[$sName], $sFullRelativeBasePath);
                     unlink($sOldPath);
                 }
                 if ($oField->isUploadImage() && !empty($oField->maxwidth) || !empty($oField->maxheight)) {
                     FlexiImageUtil::imageResize($oField->maxwidth, $oField->maxheight, $aStatus["path"]);
                 }
                 //if savepath not declared, full path from root is saved
                 //  if declared, only save filename
                 //  "" => use base root path
                 //resize image based on max width, height
                 //FlexiImageUtil::imageResize(345, 287, $aStatus["path"]);
                 $oStore[$sName] = FlexiFileUtil::getRelativePathFrom($aStatus["path"], $sFullRelativeBasePath);
             } else {
                 //No file
             }
         } else {
             if (is_string($oForm[$sName])) {
                 //could be manually saved or from old path
                 $sNewFile = $oForm[$sName];
                 //delete old file if different from new file
                 if (!empty($oCurrentRow[$sName]) && !empty($sNewFile)) {
                     $sOldPath = FlexiFileUtil::getFullPathFrom($oCurrentRow[$sName], $sFullRelativeBasePath);
                     $sNewPath = FlexiFileUtil::getFullPathFrom($sNewFile, $sFullRelativeBasePath);
                     $sOldPathReal = realpath($sOldPath);
                     if (!empty($sOldPathReal) && $sOldPathReal != realpath($sNewPath)) {
                         unlink($sOldPathReal);
                     }
                 }
                 $oStore[$sName] = FlexiFileUtil::getRelativePathFrom($sNewFile, $sFullRelativeBasePath);
             } else {
                 throw new Exception("Invalid upload value: " . $oForm[$sName]);
             }
         }
         //else error
     }
     //if single file
 }
Esempio n. 3
0
 public function getFieldInput(FlexiTableFieldObject $oField, $oRow)
 {
     $sName = $oField->getName();
     $aResult = array("#name" => $this->getFieldInputName($sName), "#id" => $this->getFieldInputName($sName) . "_" . FlexiStringUtil::createRandomPassword(8), "#title" => $oField->label, "#required" => $oField->cannull == 1 ? false : true, "#default_value" => $oField->getPHPDefaultValue(), "#dbfield" => $sName, "#insert" => $oField->caninsert, "#update" => $oField->canupdate);
     switch ($oField->type) {
         case "string":
         case "int":
         case "tinyint":
         case "smallint":
         case "mediumint":
         case "bigint":
         case "money":
         case "decimal":
         case "double":
         case "email":
             $aResult["#type"] = "textfield.raw";
             break;
         case "html":
             $aResult["#type"] = "html.raw";
             break;
         case "text":
             $aResult["#type"] = "textarea.raw";
             break;
         case "select-text":
         case "select-tinyint":
         case "select-smallint":
         case "select-bigint":
         case "select-mediumint":
         case "select-enum":
         case "select-int":
         case "select-char":
             $aResult["#type"] = "select.raw";
             $aResult["#options"] = $oField->getOptions();
             break;
         case "check-char":
         case "check-varchar":
         case "check-text":
             $aResult["#type"] = "checkboxes.raw";
             $aResult["#options"] = $oField->getOptions();
             $aResult["#multiple"] = true;
             break;
         case "json":
             $aResult["#type"] = "textarea.raw";
             break;
         case "date":
             $aResult["#type"] = "date.raw";
             break;
         case "datetime":
             $aResult["#type"] = "datetime.raw";
             break;
         case "timestamp":
         case "timestamp-int":
             $aResult["#type"] = "datetime.raw";
             break;
         case "monthyear":
             $aResult["#type"] = "datemonthyear.raw";
             break;
         case "file-varchar":
         case "file-text":
             $aResult["#type"] = "file.raw";
             $aResult["#savepath"] = $oField->savepath;
             break;
         case "image-varchar":
         case "image-text":
             $aResult["#type"] = "image.raw";
             $aResult["#maximagewidth"] = $this->iMaxImageWidth;
             $aResult["#savepath"] = $oField->savepath;
             break;
         case "multiimage-text":
             $aResult["#type"] = "multiimage.raw";
             $aResult["#maximagewidth"] = $this->iMaxImageWidth;
             $aResult["#savepath"] = $oField->savepath;
             $aResult["#uploadcount"] = $oField->uploadcount;
             $aResult["#uploadseparator"] = $oField->uploadseparator;
             break;
         case "hidden":
             $aResult["#type"] = "hidden.raw";
             break;
         case "html-tiny":
             $aResult["#type"] = "html.raw";
             break;
         default:
             throw new Exception("Unsupported type: " . $oField->type);
     }
     if (!empty($oField->formsize)) {
         if (substr($oField->type, 0, 4) == "html" || substr($oField->type, 0, 4) == "text" || substr($oField->type, 0, 4) == "json") {
             $aSize = explode(",", $oField->formsize);
             $aResult["#cols"] = $aSize[0];
             if (count($aSize) >= 2) {
                 $aResult["#rows"] = $aSize[1];
             }
         } else {
             //default
             $aResult["#size"] = $oField->formsize;
         }
     } else {
     }
     if (isset($oRow[$sName])) {
         $sValue = $oRow[$sName];
         switch ($oField->type) {
             case "date":
             case "datetime":
                 //dont need this as actual value is already hidden
                 if ($sValue == "0000-00-00" || $sValue == "0000-00-00 00:00:00") {
                     $sValue = "";
                 }
                 break;
             case "timestamp":
                 if (empty($sValue)) {
                     $sValue = "";
                 } else {
                     $sValue = date("Y-m-d H:i:s", $sValue);
                 }
                 breal;
             case "check-char":
             case "check-varchar":
             case "check-text":
                 $sValue = empty($sValue) ? array() : explode($oField->uploadseparator, $sValue);
                 break;
         }
         //switch
         $aResult["#value"] = $sValue;
     }
     return $aResult;
 }