Exemplo n.º 1
0
 public function apply()
 {
     $new_locale = $this->choose_language->getNewValue();
     require "{$this->i18n_dir}/{$new_locale}.php";
     $p4a = P4A::singleton();
     $p4a->i18n->setLocale($new_locale);
     $p4a->i18n->mergeTranslation($msg);
     $p4a->showPrevMask(true);
 }
Exemplo n.º 2
0
 public function getRows($num_page, $rows)
 {
     $p4a = P4A::singleton();
     $aReturn = array();
     $aCols = $this->getVisibleCols();
     $enabled = $this->isEnabled();
     if ($this->isActionTriggered('beforedisplay')) {
         $rows = $this->actionHandler('beforedisplay', $rows);
     }
     $pk = $this->data->getPK();
     $i = 0;
     $j = 0;
     $z = 0;
     $obj_id = $this->getID();
     foreach ($rows as $row) {
         $pk_value = $row[$pk];
         $pk_value_64 = base64_encode($pk_value);
         foreach ($aCols as $col_name) {
             if ($this->cols->{$col_name}->isEnabled() and ($this->cols->{$col_name}->getType() == "action" or isset($this->data->fields->{$col_name}) and !$this->data->fields->{$col_name}->isReadOnly())) {
                 $col_enabled = true;
                 $cell_id = $obj_id . '_' . $pk_value_64 . '_' . $z;
                 $z++;
             } else {
                 $cell_id = "";
                 $col_enabled = false;
             }
             $aReturn[$i]['cells'][$j]['class'] = ($enabled and $col_enabled) ? 'p4a_grid_td p4a_grid_td_enabled' : 'p4a_grid_td p4a_grid_td_disabled';
             $aReturn[$i]['cells'][$j]['clickable'] = ($enabled and $col_enabled) ? 'clickable' : '';
             $aReturn[$i]['cells'][$j]['id'] = $cell_id;
             $aReturn[$i]['cells'][$j]['title'] = $col_name;
             if ($this->cols->{$col_name}->getType() == "action") {
                 $aReturn[$i]['cells'][$j]['value'] = __($this->cols->{$col_name}->getLabel());
                 $aReturn[$i]['cells'][$j]['type'] = 'action';
                 if ($col_enabled) {
                     $aReturn[$i]['cells'][$j]['clickable'] = 'clickable';
                     $aReturn[$i]['cells'][$j]['action'] = $this->cols->{$col_name}->composeStringActions(array($i, $col_name));
                 } else {
                     $aReturn[$i]['cells'][$j]['action'] = $enabled ? $this->cols->{$col_name}->composeStringActions(array($i, $col_name)) : '';
                 }
             } elseif ($this->cols->{$col_name}->isFormatted()) {
                 if ($this->cols->{$col_name}->isActionTriggered('onformat')) {
                     $aReturn[$i]['cells'][$j]['value'] = $this->cols->{$col_name}->actionHandler('onformat', $row[$col_name], $this->data->fields->{$col_name}->getType(), $this->data->fields->{$col_name}->getNumOfDecimals());
                 } else {
                     $aReturn[$i]['cells'][$j]['value'] = $p4a->i18n->format($row[$col_name], $this->data->fields->{$col_name}->getType(), $this->data->fields->{$col_name}->getNumOfDecimals(), false);
                 }
             } else {
                 $aReturn[$i]['cells'][$j]['value'] = $row[$col_name];
             }
             if (!isset($aReturn[$i]['cells'][$j]['type'])) {
                 $aReturn[$i]['cells'][$j]['type'] = $this->data->fields->{$col_name}->getType();
             }
             $j++;
         }
         $i++;
     }
     return $aReturn;
 }
Exemplo n.º 3
0
 private function setFieldsProperties()
 {
     $this->fields->product_id->setLabel("Product ID")->setWidth(198)->setTooltip("This ID is automatically generated and you cannot modify it")->enable(false);
     $this->fields->category_id->setType("select")->setSource(P4A::singleton()->categories)->setSourceDescriptionField("description")->setLabel("Category")->setTooltip("Choose a category from the list")->setWidth(200);
     $this->fields->brand_id->setLabel("Brand")->setWidth(200)->setTooltip("Choose a brand from the list")->setType("select")->setSource(P4A::singleton()->brands)->setSourceDescriptionField("description");
     $this->fields->model->setWidth(198);
     $this->fields->date_arrival->setWidth(178);
     $this->fields->discount->setLabel("Discount %")->setWidth(40);
     $this->fields->price->setLabel("Price \$")->setWidth(40);
     $this->fields->picture->setType("file");
     $this->fields->description->setType("rich_textarea")->enableUpload();
 }
Exemplo n.º 4
0
 public function nextItem()
 {
     $p4a = P4A::singleton();
     if ($this->_pointer < $this->getNumItems()) {
         $id = $this->_objects[$this->_pointer];
         $this->_pointer++;
         if (!isset($p4a->objects[$id]) or !is_object($p4a->objects[$id])) {
             $this->_pointer--;
             unset($this->_objects[$this->_pointer]);
             $this->_objects = array_values($this->_objects);
             return $this->nextItem();
         } else {
             return $p4a->objects[$id];
         }
     } else {
         $this->_pointer = 0;
         $ret = null;
         //php 4.4 fix
         return $ret;
     }
 }
Exemplo n.º 5
0
/**
 * @param string $file
 * @param boolean $new_window Only works within AJAX calls
 * @throws P4A_Exception if the file does not exists in P4A_UPLOADS_DIR
 */
function P4A_Redirect_To_File($file, $new_window = false)
{
    if (!@file_exists(@realpath(P4A_UPLOADS_DIR . "/{$file}"))) {
        throw new P4A_Exception("The requested file does not exists within P4A_UPLOADS_DIR", P4A_FILESYSTEM_ERROR);
    }
    $p4a = P4A::singleton();
    $file = urlencode($file);
    $file = "index.php?_p4a_download_file={$file}";
    if ($p4a->inAjaxCall()) {
        $gmdate = gmdate("D, d M Y H:i:s");
        header('Content-type: text/xml; 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");
        ob_start();
        echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
        echo "<ajax-response action_id=\"" . $p4a->getActionHistoryId() . "\" focus_id=\"\">\n";
        foreach ($p4a->getRenderedMessages() as $message) {
            echo "\n<message><![CDATA[{$message}]]></message>";
        }
        echo "<widget id='p4a'>\n";
        if ($new_window) {
            echo "<javascript_pre><![CDATA[window.open('{$file}')]]></javascript_pre>\n";
        } else {
            echo "<javascript_pre><![CDATA[window.location='{$file}']]></javascript_pre>\n";
        }
        echo "</widget>\n";
        echo "</ajax-response>";
        if (P4A_AJAX_DEBUG) {
            if (($fp = @fopen(P4A_AJAX_DEBUG, 'w')) !== false) {
                @fwrite($fp, ob_get_contents());
                @fclose($fp);
            }
        }
        ob_end_flush();
        die;
        /* JSON OUTPUT DISABLED
        		$gmdate = gmdate("D, d M Y H:i:s");
        		header('Content-type: text/plain; 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");
        		
        		$tmp = new p4a_ajax_response_widget("p4a", null);
        		if ($new_window) {
        			$tmp->javascript_pre = "window.open('$file')";
        		} else {
        			$tmp->javascript_pre = "window.location='$file'";
        		}
        
        		$resp = new p4a_ajax_response();
        		$resp->action_id = $p4a->getActionHistoryId();
        		$resp->messages = $p4a->getRenderedMessages();
        		$resp->widgets[] = $tmp;
        		
        		ob_start();
        		require_once "Zend/Json.php";
        		echo Zend_Json::encode($resp);
        		
        		if (P4A_AJAX_DEBUG) {
        			if (($fp = @fopen(P4A_AJAX_DEBUG, 'w')) !== false) {
        				@fwrite($fp, ob_get_contents());
        				@fclose($fp);
        			}
        		}
        
        		ob_end_flush();
        		die();
        		*/
    }
    header("Location: {$file}");
    die;
}
Exemplo n.º 6
0
 protected function getChildrenAsString()
 {
     $string = "";
     $p4a = P4A::singleton();
     $handheld = p4a::singleton()->isHandheld();
     foreach ($this->_map as $objs) {
         $one_visible = false;
         $row = "\n<div class='row'>";
         foreach ($objs as $obj) {
             $classes = array("col");
             $object = $p4a->getObject($obj["id"]);
             if (is_object($object)) {
                 $as_string = $object->getAsString();
             } else {
                 unset($p4a->objects[$obj["id"]]);
                 unset($this->_map[$i][$j]);
                 if (empty($this->_map[$i])) {
                     unset($this->_map[$i]);
                 }
                 $as_string = '';
             }
             if (strlen($as_string) > 0) {
                 if ($obj["float"] == "none") {
                     $obj["float"] = "left";
                     $obj["margin"] = 0;
                     $classes[] = "p4a_frame_anchor_center";
                 }
                 $one_visible = true;
                 $float = $obj["float"];
                 $margin = "margin-" . $obj["float"];
                 $margin_value = $obj["margin"];
                 $as_string = "\n\t\t{$as_string}";
                 if ($handheld) {
                     $row .= $as_string;
                 } else {
                     $display = $object->isVisible() ? 'block' : 'none';
                     $class = empty($classes) ? '' : 'class="' . implode(' ', $classes) . '"';
                     $row .= "\n\t<div {$class} style='display:{$display};float:{$float};{$margin}:{$margin_value}'>{$as_string}\n\t</div>";
                 }
             }
         }
         $row .= "\n</div>\n";
         if ($one_visible) {
             $string .= $row;
         }
     }
     return $string;
 }
Exemplo n.º 7
0
 private function addDefaultButtons()
 {
     $this->addButton('print', 'actions/document-print')->dropAction('onclick')->setProperty('onclick', 'window.print(); return false;')->setAccessKey("P");
     $this->addButton('exit', 'actions/window-close', 'right')->setLabel("Go back to the previous mask")->setAccessKey("X")->implement('onclick', P4A::singleton(), 'showPrevMask');
 }
Exemplo n.º 8
0
 /**
  * Renders HTML
  * @access public
  * @return string
  */
 public function getAsString()
 {
     $id = $this->getId();
     if (!$this->isVisible()) {
         return "<div id='{$id}' class='hidden'></div>";
     }
     $has_items = $this->hasItems() ? "class='p4a_menu_has_items'" : '';
     $properties = $this->composeStringProperties();
     if (P4A::singleton()->isHandheld()) {
         $icon = '';
     } else {
         $icon = $this->getIcon();
         if (strlen($icon)) {
             if (strpos($this->_icon, '.') === false) {
                 $icon_disabled = '';
                 if (!$this->isEnabled()) {
                     $icon_disabled = '_disabled';
                 }
                 $icon = P4A_ICONS_PATH . "/16/{$icon}{$icon_disabled}." . P4A_ICONS_EXTENSION;
             }
             $icon = "<img src='{$icon}' alt='' />";
         }
     }
     if (empty($this->_map_actions["onclick"]["method"]) or !$this->isEnabled()) {
         $sReturn = "<li {$has_items}>" . P4A_Generate_Widget_Layout_Table($icon, "<div {$properties}>" . __($this->getLabel()) . "</div>");
     } else {
         $actions = $this->composeStringActions();
         $sReturn = "<li {$has_items}>" . P4A_Generate_Widget_Layout_Table($icon, "<a href='#' {$actions} {$properties}>" . P4A_Highlight_AccessKey(__($this->getLabel()), $this->getAccessKey()) . "</a>");
     }
     if ($has_items) {
         $sReturn .= "<ul>";
         while ($item = $this->items->nextItem()) {
             $sReturn .= $item->getAsString();
         }
         $sReturn .= "</ul>";
     }
     $sReturn .= "</li>";
     return $sReturn;
 }
Exemplo n.º 9
0
 /**
  * Returns the HTML rendered field as image upload
  * @return string
  */
 public function getAsImage()
 {
     if ($this->getNewValue() === null) {
         return $this->getAsFile();
     }
     $mime_type = explode('/', $this->getNewValue(3));
     $mime_type = $mime_type[0];
     if ($mime_type != 'image') {
         return $this->getAsFile();
     }
     $sReturn = '<table>';
     if (P4A_GD) {
         $src = $this->getNewValue(1);
         $sReturn .= '<tr><td colspan="2"><img alt="' . __('Preview') . '" src=".?_p4a_image_thumbnail=' . urlencode("{$src}&{$this->max_thumbnail_size}") . '" /></td></tr>';
     }
     $this->buttons->button_file_preview->enable();
     $name = $this->getNewValue(6);
     if (strlen($name) == 0) {
         $name = $this->getNewValue(0);
     }
     $sReturn .= '<tr><th>' . __('Name') . ':</th><td>' . $name . '</td></tr>';
     $sReturn .= '<tr><th>' . __('Size') . ':</th><td>' . P4A::singleton()->i18n->format($this->getNewValue(2) / 1024, "decimal") . ' KB</td></tr>';
     $sReturn .= '<tr><th>' . __('Type') . ':</th><td>' . $this->getNewValue(3) . '</td></tr>';
     $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>';
     return $this->composeLabel() . $sReturn;
 }
Exemplo n.º 10
0
 public function main()
 {
     parent::main();
     P4A::singleton()->close();
 }
Exemplo n.º 11
0
 /**
  * @return P4A_Widget
  */
 public function redesign()
 {
     P4A::singleton()->redesign($this->getId());
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Handle an error action implemented by the object.
  * Checks if the the specified action is triggered and calls it,
  * if the action is not triggered calls the general error handler
  * for the object.
  * @param string $action
  * @param mixed $param Parameter(s) that will be passed to the error handler
  * @return unknown
  */
 public function errorHandler($action, $param = null)
 {
     $p4a = P4A::singleton();
     $interceptor = null;
     $method = null;
     if (array_key_exists($action, $this->_map_actions)) {
         $interceptor =& $this->_map_actions[$action]['object'];
         $method = $this->_map_actions[$action]['method'];
     } elseif (array_key_exists('onError', $this->_map_actions)) {
         $interceptor =& $this->_map_actions['onError']['object'];
         $method = $this->_map_actions['onError']['method'];
     } elseif (isset($p4a) and array_key_exists('onError', $p4a->_map_actions)) {
         $interceptor =& $p4a->_map_actions['onError']['object'];
         $method = $p4a->_map_actions['onError']['method'];
     }
     if ($interceptor !== null) {
         if ($param !== null) {
             return eval('return $interceptor->' . $method . '($param);');
         } else {
             return eval('return $interceptor->' . $method . '();');
         }
     } else {
         ob_start();
         $p4a->openMask('p4a_mask_error');
         $p4a->active_mask->main($param);
         $p4a->close();
         ob_end_flush();
         return ABORT;
     }
 }
Exemplo n.º 13
0
 /**
  * Prints out an info message (with an info icon).
  * It's a wrapper for P4A::message()
  * @param string $message
  * @return P4A_Mask
  */
 public function info($message)
 {
     P4A::singleton()->messageInfo($message);
     return $this;
 }
Exemplo n.º 14
0
?>
 container">
<div id='p4a_body' class='p4a_browser_<?php 
echo P4A::singleton()->getBrowserOS();
?>
'>
<div id='p4a_loading'>
	<img src='<?php 
echo P4A_THEME_PATH;
?>
/loading.gif' alt='' /> <?php 
echo __('Loading...');
?>
	<div id='p4a_loading_percentage'></div>
</div>
<div class='p4a_system_messages'>
	<div class='p4a_system_messages_inner'>
		<?php 
foreach (P4A::singleton()->getRenderedMessages() as $message) {
    ?>
		<div class='p4a_system_message'><?php 
    echo $message;
    ?>
</div>
		<?php 
}
?>
	</div>
</div>
<?php 
echo $this->maskOpen();
Exemplo n.º 15
0
 public function setNumElementsOnPage()
 {
     $elements = (int) $this->buttons->elements_page->getNewValue();
     if ($elements < 0) {
         $elements = 0;
     }
     $parent = P4A::singleton()->getObject($this->getParentID());
     $parent->data->setPageLimit($elements);
     $parent->redesign();
 }
Exemplo n.º 16
0
 /**
  * @return string
  */
 public function getAsString()
 {
     $id = $this->getId();
     if (!$this->isVisible()) {
         return "<div id='{$id}' class='hidden'></div>";
     }
     $p4a = P4A::singleton();
     $properties = $this->composeStringProperties();
     $actions = $this->composeStringActions();
     $class = $this->composeStringClass();
     $string = "<table id='{$id}' {$properties} {$actions} {$class}>\n";
     for ($i = 1; $i <= $this->_rows; $i++) {
         $string .= "<tr>\n";
         for ($j = 1; $j <= $this->_cols;) {
             if (is_string($this->_map[$i][$j])) {
                 $j++;
                 continue;
             }
             $rowspan = 1;
             $colspan = 1;
             $obj_as_string = "&nbsp;";
             if (is_array($this->_map[$i][$j])) {
                 $cell = $this->_map[$i][$j];
                 $obj = $p4a->getObject($cell[0]);
                 if ($obj === null) {
                     $obj_as_string = $cell[0];
                 } else {
                     $obj_as_string = $obj->getAsString();
                 }
                 $rowspan = $cell[1];
                 $colspan = $cell[2];
             }
             $string .= "<td rowspan='{$rowspan}' colspan='{$colspan}'>{$obj_as_string}</td>\n";
             $j += $colspan;
         }
         $string .= "</tr>\n";
     }
     $string .= "</table>\n";
     return $string;
 }
Exemplo n.º 17
0
 /**
  * Event interceptor when user moves an element to another subtree
  */
 public function onMovement()
 {
     $this->redesign();
     $table = $this->source->getTable();
     $pk = $this->source->getPk();
     $current = $this->source->fields->{$pk}->getValue();
     $field = P4A::singleton()->getObject($this->field_to_update_on_movement);
     $new_value = $field->getNormalizedNewValue();
     $receiver_path = $this->getPath($new_value, $table, $pk);
     foreach ($receiver_path as $record) {
         if ($current == $record[$pk]) {
             return;
         }
     }
     if ($this->actionHandler('beforeMovement') == ABORT) {
         return ABORT;
     }
     if ($new_value != $current) {
         if (strlen($new_value)) {
             P4A_DB::singleton($this->source->getDSN())->adapter->query("UPDATE {$table} SET {$this->recursor} = ? WHERE {$pk} = ?", array($new_value, $current));
         } else {
             P4A_DB::singleton($this->source->getDSN())->adapter->query("UPDATE {$table} SET {$this->recursor} = NULL WHERE {$pk} = ?", array($current));
         }
     }
     return $this->actionHandler('afterMovement');
 }
Exemplo n.º 18
0
?>
post, 200);
		return;
	}

	CKEDITOR.replace('<?php 
echo $this->getId();
?>
input', {
		p4a_instance_id: '<?php 
echo $this->getId();
?>
input',
		autoUpdateElement: false,
		language: '<?php 
echo P4A::singleton()->i18n->getLanguage();
?>
',
		width: '<?php 
echo $this->getWidth();
?>
',
		height: '<?php 
echo $this->getHeight();
?>
',
		resize_enabled: false,
		toolbarCanCollapse: false,
		coreStyles_strike: {element: 'span', attributes: {'style': 'text-decoration:line-through'}},
		coreStyles_underline: {element: 'span', attributes: {'style': 'text-decoration:underline'}},
		forcePasteAsPlainText: true,