/** * Retrive data for the current page * @return array */ public function getRows($num_page, $rows) { $p4a = P4A::singleton(); $aReturn = array(); $parent = $p4a->getObject($this->getParentID()); $num_page_from_data_source = $parent->data->getNumPage(); $aCols = $parent->getVisibleCols(); $limit = $parent->data->getPageLimit(); $offset = $parent->data->getOffset(); $enabled = $this->isEnabled(); $action = null; if ($this->isActionTriggered('beforedisplay')) { $rows = $this->actionHandler('beforedisplay', $rows); } $i = 0; foreach ($rows as $row_number => $row) { $j = 0; $aReturn[$i]['row']['even'] = $i % 2 == 0; if ($num_page == $num_page_from_data_source and $row_number + $offset + 1 == $parent->data->getRowNumber()) { $aReturn[$i]['row']['active'] = true; } else { $aReturn[$i]['row']['active'] = false; } if (isset($row['_p4a_enabled'])) { $row_enabled = $row['_p4a_enabled']; } else { $row_enabled = true; } foreach ($aCols as $col_name) { $col_enabled = $parent->cols->{$col_name}->isEnabled(); $aReturn[$i]['cells'][$j]['action'] = ($enabled and $row_enabled and $col_enabled) ? $this->composeStringActions(array($row_number, $col_name)) : ''; $aReturn[$i]['cells'][$j]['clickable'] = ($enabled and $row_enabled and $col_enabled) ? 'clickable' : ''; if ($parent->cols->{$col_name}->data) { $aReturn[$i]['cells'][$j]['value'] = $parent->cols->{$col_name}->getDescription($row[$col_name]); $aReturn[$i]['cells'][$j]['type'] = $parent->data->fields->{$col_name}->getType(); } elseif ($parent->cols->{$col_name}->getType() == "image") { $value = $row[$col_name]; if (!empty($value)) { $value = substr($value, 1, -1); $value = explode(',', $value); list($type) = explode('/', $value[3]); if ($type == 'image') { if (P4A_GD) { try { $thumb = new P4A_Thumbnail_Generator(); $thumb->setCacheDir(P4A_UPLOADS_TMP_DIR)->setMaxWidth(P4A_TABLE_THUMB_HEIGHT)->setMaxHeight(P4A_TABLE_THUMB_HEIGHT)->setFilename(P4A_Strip_Double_Slashes(P4A_UPLOADS_DIR . $value[1]))->processFile()->cacheThumbnail(); $image_src = P4A_UPLOADS_TMP_PATH . '/' . $thumb->getCachedFilename(); $aReturn[$i]['cells'][$j]['value'] = "<img src='{$image_src}' alt='' />"; } catch (Exception $e) { $aReturn[$i]['cells'][$j]['value'] = ""; } } else { $image_src = P4A_UPLOADS_PATH . $value[1]; $aReturn[$i]['cells'][$j]['value'] = "<img src='{$image_src}' height='{$thumb_height}' alt='' />"; } } else { $aReturn[$i]['cells'][$j]['value'] = $value[0]; } } else { $aReturn[$i]['cells'][$j]['value'] = ''; } $aReturn[$i]['cells'][$j]['type'] = $parent->data->fields->{$col_name}->getType(); } elseif ($parent->cols->{$col_name}->getType() == "action") { $aReturn[$i]['cells'][$j]['value'] = __($parent->cols->{$col_name}->getLabel()); $aReturn[$i]['cells'][$j]['type'] = 'action'; if ($row_enabled and $col_enabled) { $aReturn[$i]['cells'][$j]['clickable'] = 'clickable'; $aReturn[$i]['cells'][$j]['action'] = $parent->cols->{$col_name}->composeStringActions(array($row_number, $col_name)); } else { $aReturn[$i]['cells'][$j]['action'] = $enabled ? $parent->cols->{$col_name}->composeStringActions(array($row_number, $col_name)) : ''; } } else { if ($parent->cols->{$col_name}->isFormatted()) { if ($parent->cols->{$col_name}->isActionTriggered('onformat')) { $aReturn[$i]['cells'][$j]['value'] = $parent->cols->{$col_name}->actionHandler('onformat', $row[$col_name], $parent->data->fields->{$col_name}->getType(), $parent->data->fields->{$col_name}->getNumOfDecimals(), $row); } else { $aReturn[$i]['cells'][$j]['value'] = $p4a->i18n->format($row[$col_name], $parent->data->fields->{$col_name}->getType(), $parent->data->fields->{$col_name}->getNumOfDecimals(), false); } } else { $aReturn[$i]['cells'][$j]['value'] = $row[$col_name]; } $aReturn[$i]['cells'][$j]['type'] = $parent->data->fields->{$col_name}->getType(); } $j++; } $i++; } return $aReturn; }
/** * Returns the HTML rendered field as file upload * @return string */ public function getAsFile() { $p4a = P4A::singleton(); $id = $this->getID(); if ($this->getNewValue() === null) { $action = 'p4a_event_execute'; if (P4A_AJAX_ENABLED) { $action .= '_ajax'; } $sReturn = "<input type='file' id='{$id}input' "; $this->intercept($this, 'onchange', 'redesign'); if (!$this->isEnabled()) { $sReturn .= 'disabled="disabled" '; } $sReturn .= $this->composeStringActions() . $this->composeStringProperties() . ' />'; } else { $this->buildDeletePreviewDownloadButtons(); if ($this->isEnabled()) { $this->buttons->button_file_delete->enable(); } else { $this->buttons->button_file_delete->disable(); } if (P4A_Thumbnail_Generator::isMimeTypeSupported($this->getNewValue(3))) { return $this->getAsImage(); } $src = P4A_UPLOADS_URL . $this->getNewValue(1); $mime_type = $this->getNewValue(3); $this->label->unsetProperty('for'); $name = $this->getNewValue(6); if (strlen($name) == 0) { $name = $this->getNewValue(0); } $sReturn = '<table>'; $sReturn .= '<tr><th>' . __('Name') . ':</th><td>' . $name . '</td></tr>'; $sReturn .= '<tr><th>' . __('Size') . ':</th><td>' . $p4a->i18n->format($this->getNewValue(2) / 1024, "decimal") . ' KB</td></tr>'; $sReturn .= '<tr><th>' . __('Type') . ':</th><td>' . $this->getNewValue(3) . '</td></tr>'; $this->buttons->button_file_preview->enable(P4A_Is_Mime_Type_Embeddable($mime_type)); $sReturn .= '<tr><td colspan="2">' . $this->buttons->button_file_preview->getAsString() . ' ' . $this->buttons->button_file_download->getAsString() . ' ' . $this->buttons->button_file_delete->getAsString() . '</td></tr>'; $sReturn .= '</table>'; } $sReturn = $this->composeLabel() . $sReturn; $this->label->setProperty('for', "{$id}input"); return $sReturn; }
/** * Never call this method if you don't know what you're doing */ public function executeExternalCommands() { if (isset($_REQUEST['_p4a_session_browser'])) { if (!empty($_REQUEST['_p4a_session_browser']) and isset($this->objects[$_REQUEST['_p4a_session_browser']])) { $obj =& $this->objects[$_REQUEST['_p4a_session_browser']]; } else { $obj =& $this; } $vars = get_object_vars($obj); ksort($vars); $name = $obj->getName(); if (empty($name)) { $name = "P4A main object"; } $name .= ' (' . get_class($obj) . ')'; echo "<h1>{$name}</h1>"; echo "<table border='1'>"; echo "<tr><th>key</th><th>value</th></tr>"; foreach ($vars as $k => $v) { $v = _P4A_Debug_Print_Variable($v); echo "<tr><td valign='top'>{$k}</td><td>{$v}</td></tr>"; } echo "</table>"; die; } elseif (isset($_REQUEST['_rte_file_manager']) and isset($_REQUEST['_object_id']) and isset($this->objects[$_REQUEST['_object_id']])) { require P4A_THEME_DIR . '/widgets/rich_textarea/filemanager/connectors/php/connector.php'; die; } elseif (isset($_REQUEST['_upload_path'])) { $path = P4A_UPLOADS_PATH; if (isset($_REQUEST['_object_id']) and isset($this->objects[$_REQUEST['_object_id']])) { $object =& $this->objects[$_REQUEST['_object_id']]; if ($object instanceof P4A_Field) { $path .= '/' . $object->getUploadSubpath(); } } echo preg_replace(array("~/+~", "~/\$~"), array('/', ''), $path); die; } elseif (isset($_REQUEST['_p4a_autocomplete'])) { if (isset($_REQUEST['_object']) and isset($_REQUEST['term']) and isset($this->objects[$_REQUEST['_object']])) { $object =& $this->objects[$_REQUEST['_object']]; $db = P4A_DB::singleton($object->data_field->getDSN()); $data =& $object->data; $old_where = $data->getWhere(); $description_field = $object->getSourceDescriptionField(); if ($object->isActionTriggered('onautocomplete')) { $this->actionHandler('onautocomplete', $data, $_REQUEST['term']); } else { $q = $db->quote($_REQUEST['term'], false); $where = $db->getCaseInsensitiveLikeSQL($description_field, "%{$q}%"); if ($old_where) { $where = "({$old_where}) AND ({$where})"; } $data->setWhere($where); } $all = $data->getAll(); $data->setWhere($old_where); $new_data = array(); $tmp = array(); foreach ($all as $row) { $tmp[$row[$description_field]] = $row[$description_field]; } ksort($tmp); foreach ($tmp as $k => $v) { $new_data[] = array("id" => $k, "label" => htmlspecialchars($k), "value" => $k); } require_once "Zend/Json.php"; echo Zend_Json::encode($new_data); } die; } elseif (isset($_REQUEST['_p4a_date_format'])) { echo $this->i18n->format($_REQUEST['_p4a_date_format'], 'date', null, false); die; } elseif (isset($_REQUEST['_p4a_time_format'])) { echo $this->i18n->format($_REQUEST['_p4a_time_format'], 'time', null, false); die; } elseif (isset($_REQUEST['_p4a_datetime_format'])) { echo $this->i18n->format($_REQUEST['_p4a_datetime_format'], 'datetime', null, false); die; } elseif (isset($_REQUEST['_p4a_image_thumbnail'])) { $image_data = explode('&', $_REQUEST['_p4a_image_thumbnail']); $thumb = new P4A_Thumbnail_Generator(); $thumb->setCacheDir(P4A_UPLOADS_TMP_DIR)->setFilename(P4A_Strip_Double_Slashes(P4A_UPLOADS_DIR . $image_data[0]))->setMaxWidth($image_data[1])->setMaxHeight($image_data[1])->processFile()->outputThumbnail(); die; } elseif (isset($_REQUEST['_p4a_download_file'])) { $file = realpath(P4A_UPLOADS_DIR . '/' . $_REQUEST['_p4a_download_file']); if (P4A_OS == "linux") { if (strpos($file, realpath(P4A_UPLOADS_DIR)) !== 0) { die; } } else { if (stripos($file, realpath(P4A_UPLOADS_DIR)) !== 0) { die; } } if ($file !== false and file_exists($file)) { $name = basename($file); $name = preg_replace("/^_p4a_.*?_/", "", $name); $gmdate = gmdate("D, d M Y H:i:s"); header("Content-Type: text/html; charset=UTF-8"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Pragma: no-cache"); header("Last-Modified: {$gmdate} GMT"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$name}\""); header("Content-Length: " . filesize($file)); $fp = fopen($file, "rb"); fpassthru($fp); fclose($fp); if (strpos($file, realpath(P4A_UPLOADS_TMP_DIR) . DIRECTORY_SEPARATOR . '_p4a_') === 0) { unlink($file); } } die; } elseif (isset($_REQUEST['_p4a_upload_progress']) and P4A_UPLOAD_PROGRESS) { $upload_info = uploadprogress_get_info($_REQUEST['_p4a_upload_progress']); if (is_array($upload_info)) { $percentage = round($upload_info["bytes_uploaded"] / $upload_info["bytes_total"] * 100) . "%"; $speed = round($upload_info["speed_average"] / 1024) . "KB/s"; echo "{$percentage} - {$speed}"; } die; } }