function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $settings = new \GCore\Libs\Parameter($form->_settings());
     $checkout_values = array('cmd' => trim($config->get('cmd')), 'business' => trim($config->get('business')), 'no_shipping' => trim($config->get('no_shipping')), 'no_note' => trim($config->get('no_note')), 'return' => trim($config->get('return')), 'currency_code' => trim($config->get('currency_code')), 'item_name' => $form->data($config->get('item_name')), 'amount' => $form->data($config->get('amount'), 0), 'first_name' => $form->data($config->get('first_name')), 'last_name' => $form->data($config->get('last_name')), 'address1' => $form->data($config->get('address1')), 'address2' => $form->data($config->get('address2')), 'city' => $form->data($config->get('city')), 'state' => $form->data($config->get('state')), 'zip' => $form->data($config->get('zip')), 'country' => $form->data($config->get('country')), 'custom' => $form->data($config->get('custom')), 'night_phone_a' => $form->data($config->get('night_phone_a')));
     if (strlen(trim($config->get('extra_params', '')))) {
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $checkout_values[$k] = $form->data($v);
         }
     }
     if ((bool) $settings->get('validated_paypal', 0) === true) {
         //$checkout_values['amount'] = $checkout_values['amount'];
     } else {
         $checkout_values['amount'] = rand(2, 5) * $checkout_values['amount'];
     }
     $fields = "";
     foreach ($checkout_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     if ((bool) $config->get('sandbox', 0) === true) {
         $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
     } else {
         $url = 'https://www.paypal.com/cgi-bin/webscr?';
     }
     if ($config->get('debug_only', 0) == 1) {
         echo $url . $fields;
     } else {
         \GCore\Libs\Env::redirect($url . $fields);
     }
 }
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $settings = new \GCore\Libs\Parameter($form->_settings());
     $DEBUGGING = $config->get('debugging');
     # Display additional information to track down problems
     $TESTING = $config->get('testing');
     # Set the testing flag so that transactions are not live
     $ERROR_RETRIES = $config->get('error_retires');
     # Number of transactions to post if soft errors occur
     $auth_net_login_id = $config->get('loginid');
     $auth_net_tran_key = $config->get('transkey');
     #  $auth_net_url				= "https://test.authorize.net/gateway/transact.dll";
     #  Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts
     #  $auth_net_url				= "https://secure.authorize.net/gateway/transact.dll";
     $authnet_values = array("x_login" => $auth_net_login_id, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_url" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $auth_net_tran_key, "x_relay_response" => "FALSE", "x_card_num" => $form->data($config->get('x_card_num'), ''), "x_exp_date" => $form->data($config->get('x_exp_date_m'), '') . $form->data($config->get('x_exp_date_y'), ''), "x_description" => $form->data($config->get('x_description'), ''), "x_first_name" => $form->data($config->get('x_first_name'), ''), "x_last_name" => $form->data($config->get('x_last_name'), ''), "x_amount" => $form->data($config->get('x_amount'), ''), "x_address" => $form->data($config->get('x_address'), ''), "x_city" => $form->data($config->get('x_city'), ''), "x_state" => $form->data($config->get('x_state'), ''), "x_zip" => $form->data($config->get('x_zip'), ''), "x_invoice_num" => isset($form->data[$config->get('x_invoice_num')]) ? $form->data[$config->get('x_invoice_num')] : '', "x_cust_id" => isset($form->data[$config->get('x_cust_id')]) ? $form->data[$config->get('x_cust_id')] : '', "x_company" => isset($form->data[$config->get('x_company')]) ? $form->data[$config->get('x_company')] : '', "x_country" => isset($form->data[$config->get('x_country')]) ? $form->data[$config->get('x_country')] : '', "x_phone" => isset($form->data[$config->get('x_phone')]) ? $form->data[$config->get('x_phone')] : '', "x_fax" => isset($form->data[$config->get('x_fax')]) ? $form->data[$config->get('x_fax')] : '', "x_email" => isset($form->data[$config->get('x_email')]) ? $form->data[$config->get('x_email')] : '');
     if (strlen(trim($config->get('extra_params', '')))) {
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $authnet_values[$k] = urlencode($form->data($v, ''));
         }
     }
     if ((bool) $settings->get('validated_authorize', 0) === true) {
     } else {
         $authnet_values['x_amount'] = rand(2, 5) * (int) $form->data($config->get('x_amount'), '');
     }
     if ($config->get('testing', 0) == 1) {
         $authnet_values['x_test_request'] = "TRUE";
     }
     $fields = "";
     foreach ($authnet_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     $nvpstr = $fields;
     if ($config->get('debugging', 0)) {
         echo $nvpstr;
     }
     if ($config->get('testing', 0)) {
         $ch = curl_init("https://test.authorize.net/gateway/transact.dll");
     } else {
         $ch = curl_init("https://secure.authorize.net/gateway/transact.dll");
     }
     //$ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); // uncomment if your transkey was created with account set to live
     curl_setopt($ch, CURLOPT_HEADER, 0);
     // set to 0 to eliminate header info from response
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Returns response data instead of TRUE(1)
     curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
     // use HTTP POST to send form data
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     // uncomment this line if you get no gateway response. ###
     $resp = curl_exec($ch);
     //execute post and get results
     curl_close($ch);
     //process the response
     $this->_processResp($resp, $form, $config);
 }
Beispiel #3
0
 public static function output($target, $event)
 {
     $return = "\$('" . $target . "').find('option').remove();";
     $options = \GCore\Libs\Str::list_to_array($event['options']);
     foreach ($options as $v => $t) {
         $return .= "\$('" . $target . "').append('<option value=\"" . $v . "\">" . $t . "</option>');" . "\n";
     }
     return $return;
 }
Beispiel #4
0
 function execute(&$form, $action_id)
 {
     $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
     $config = new \GCore\Libs\Parameter($config);
     $r_params = array();
     if (strlen(trim($config->get('extra_params', '')))) {
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $r_params[$k] = $form->data($v);
         }
     }
     $url = \GCore\Libs\Url::buildQuery($config->get('url', ''), $r_params);
     if (strlen($config->get('url', ''))) {
         \GCore\Libs\Env::redirect($url);
     }
 }
Beispiel #5
0
 function execute(&$form, $action_id)
 {
     $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
     $config = new \GCore\Libs\Parameter($config);
     if (function_exists('curl_init')) {
         $form->debug[$action_id][self::$title][] = "CURL OK : the CURL function was found on this server.";
     } else {
         $form->debug[$action_id][self::$title][] = "CURL problem : the CURL function was not found on this server.";
         $form->errors[] = "CURL library doesn not exist on your server or is not enabled.";
         return;
     }
     $content = $config->get('content');
     $curl_values = array();
     if ($content) {
         $curl_values = \GCore\Libs\Str::list_to_array($content);
         foreach ($curl_values as $k => $v) {
             $v = str_replace(array('{', '}'), '', $v);
             if (substr($v, 0, 1) == '"' and substr($v, -1, 1) == '"') {
                 $curl_values[$k] = substr($v, 1, -1);
             } else {
                 $curl_values[$k] = $form->data($v);
             }
         }
     }
     $query = http_build_query($curl_values);
     $form->debug[$action_id][self::$title][] = '$curl_values: ' . print_r($query, true);
     $form->debug[$action_id][self::$title][] = 'curl_target_url: ' . $config->get('target_url');
     $ch = curl_init($config->get('target_url'));
     curl_setopt($ch, CURLOPT_HEADER, $config->get('header_in_response', 0));
     // set to 0 to eliminate header info from response
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Returns response data instead of TRUE(1)
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
     // use HTTP POST to send form data
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     $response = curl_exec($ch);
     //execute post and get results
     $form->debug[$action_id][self::$title][] = 'curl_errors: ' . curl_error($ch);
     $form->debug[$action_id][self::$title][] = 'curl_info: ' . print_r(curl_getinfo($ch), true);
     curl_close($ch);
     //add the response in the form data array
     $form->data['curl'] = $response;
 }
Beispiel #6
0
 function execute(&$form, $action_id)
 {
     $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
     $config = new \GCore\Libs\Parameter($config);
     $r_params = array();
     if (strlen(trim($config->get('extra_params', '')))) {
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $v = str_replace(array('{', '}'), '', $v);
             if (substr($v, 0, 1) == '"' and substr($v, -1, 1) == '"') {
                 $r_params[$k] = substr($v, 1, -1);
             } else {
                 $r_params[$k] = $form->data($v);
             }
         }
     }
     $url = \GCore\Libs\Url::buildQuery($config->get('url', ''), $r_params);
     if (strlen($config->get('url', ''))) {
         \GCore\Libs\Env::redirect($url);
     }
 }
Beispiel #7
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $settings = new \GCore\Libs\Parameter($form->_settings());
     $this->_DEBUGGING = $config->get('debugging', 0);
     $this->_TESTING = $config->get('sandbox', 0);
     $this->_API_UserName = $config->get('API_USERNAME');
     $this->_API_Password = $config->get('API_PASSWORD');
     $this->_API_Signature = $config->get('API_SIGNATURE');
     //$API_ENDPOINT			= $config->get('API_ENDPOINT');
     if ((int) $config->get('sandbox', 0) == 1) {
         $this->_API_Endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
     } else {
         $this->_API_Endpoint = 'https://api-3t.paypal.com/nvp';
     }
     if ((int) $config->get('USE_PROXY') == 1) {
         $this->_USE_PROXY = TRUE;
     } else {
         $this->_USE_PROXY = FALSE;
     }
     $this->_PROXY_HOST = $config->get('PROXY_HOST', '');
     $this->_PROXY_PORT = $config->get('PROXY_PORT', '');
     //$PAYPAL_URL			= $config->get('PAYPAL_URL;
     $this->_version = '56.0';
     $paypal_values = array("PAYMENTACTION" => urlencode($config->get('PAYMENTACTION', 'Sale')), "EXPDATE" => str_pad(urlencode($form->data($config->get('EXPDATE_m'))), 2, '0', STR_PAD_LEFT) . urlencode($form->data($config->get('EXPDATE_y'))), "AMT" => urlencode($form->data($config->get('AMT'))), "CREDITCARDTYPE" => urlencode($form->data($config->get('CREDITCARDTYPE'))), "ACCT" => urlencode($form->data($config->get('ACCT'))), "CVV2" => urlencode($form->data($config->get('CVV2'))), "FIRSTNAME" => urlencode($form->data($config->get('FIRSTNAME'))), "LASTNAME" => urlencode($form->data($config->get('LASTNAME'))), "STREET" => urlencode($form->data($config->get('STREET'))), "CITY" => urlencode($form->data($config->get('CITY'))), "STATE" => urlencode($form->data($config->get('STATE'))), "ZIP" => urlencode($form->data($config->get('ZIP'))), "COUNTRYCODE" => urlencode($form->data($config->get('COUNTRYCODE'))), "CURRENCYCODE" => urlencode($form->data($config->get('CURRENCYCODE'))));
     if (strlen(trim($config->get('extra_params', '')))) {
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $paypal_values[$k] = $k . ": " . urlencode($form->data($v, ''));
         }
     }
     if ((bool) $settings->get('validated_paypal', 0) === true) {
     } else {
         $paypal_values["AMT"] = rand(2, 5) * $paypal_values["AMT"];
     }
     $fields = "";
     foreach ($paypal_values as $key => $value) {
         $fields .= "&{$key}=" . $value;
     }
     if ((int) $config->get('sandbox', 0)) {
         $PAYPAL_URL = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
     } else {
         $PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
     }
     /* Construct the request string that will be sent to PayPal.
        The variable $nvpstr contains all the variables and is a
        name value pair string with & as a delimiter */
     $nvpstr = $fields;
     if ($config->get('debugging', 0) == 1) {
         echo $nvpstr;
     }
     /* Make the API call to PayPal, using API signature.
        The API response is stored in an associative array called $resArray */
     $resArray = $this->hash_call("doDirectPayment", $nvpstr);
     $form->data['paypal_pro']['transaction_id'] = isset($resArray['TRANSACTIONID']) ? $resArray['TRANSACTIONID'] : '';
     $form->data['paypal_pro']['error_message'] = $resArray['L_LONGMESSAGE0'];
     $form->data['paypal_pro']['error_code'] = $resArray['L_ERRORCODE0'];
     $form->data['paypal_pro']['correlation_id'] = $resArray['CORRELATIONID'];
     $form->data['paypal_pro']['avs_code'] = isset($resArray['AVSCODE']) ? $resArray['AVSCODE'] : '';
     /* Display the API response back to the browser.
        If the response from PayPal was a success, display the response parameters'
        If the response was an error, display the errors received using APIError.php.
        */
     $ack = strtoupper($resArray["ACK"]);
     $form->data['paypal_pro']['payment_status'] = $ack;
     //set the events
     if ($ack != "SUCCESS") {
         $this->events['fail'] = 1;
     } else {
         $this->events['success'] = 1;
     }
     //do the debug
     if ((int) $config->get('debugging', 0) == 1) {
         if ($ack != "SUCCESS") {
             $_SESSION['reshash'] = $resArray;
             $this->APIERROR($resArray);
         } else {
             $_SESSION['reshash'] = $resArray;
             $this->APISUCCESS($resArray);
         }
     }
 }
Beispiel #8
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $settings = new \GCore\Libs\Parameter($form->_settings());
     $checkout_values = array('sid' => trim($config->get('sid')), 'product_id' => $form->data($config->get('product_id'), ''), 'quantity' => $form->data($config->get('quantity'), ''), 'merchant_order_id' => isset($form->data[$config->get('merchant_order_id')]) ? $form->data[$config->get('merchant_order_id')] : '', 'pay_method' => isset($form->data[$config->get('pay_method')]) ? $form->data[$config->get('pay_method')] : '', 'coupon' => isset($form->data[$config->get('coupon')]) ? $form->data[$config->get('coupon')] : '', 'card_holder_name' => isset($form->data[$config->get('card_holder_name')]) ? $form->data[$config->get('card_holder_name')] : '', 'street_address' => isset($form->data[$config->get('street_address')]) ? $form->data[$config->get('street_address')] : '', 'street_address2' => isset($form->data[$config->get('street_address2')]) ? $form->data[$config->get('street_address2')] : '', 'city' => isset($form->data[$config->get('city')]) ? $form->data[$config->get('city')] : '', 'state' => isset($form->data[$config->get('state')]) ? $form->data[$config->get('state')] : '', 'zip' => isset($form->data[$config->get('zip')]) ? $form->data[$config->get('zip')] : '', 'country' => isset($form->data[$config->get('country')]) ? $form->data[$config->get('country')] : '', 'email' => isset($form->data[$config->get('email')]) ? $form->data[$config->get('email')] : '', 'phone' => isset($form->data[$config->get('phone')]) ? $form->data[$config->get('phone')] : '', 'lang' => isset($form->data[$config->get('lang')]) ? $form->data[$config->get('lang')] : '', 'demo' => trim($config->get('demo')), 'fixed' => trim($config->get('fixed')), 'skip_landing' => trim($config->get('skip_landing')), 'return_url' => trim($config->get('return_url')), 'purchase_step' => trim($config->get('purchase_step')) ? trim($config->get('purchase_step')) : null, 'x_Receipt_Link_URL' => trim($config->get('x_Receipt_Link_URL')));
     if ($config->get('parameter_set') == '2CO') {
         unset($checkout_values['product_id']);
         unset($checkout_values['quantity']);
         $checkout_values['mode'] = '2CO';
         $hs_params = array('type', 'name', 'quantity', 'price', 'tangible', 'product_id', 'description', 'recurrence', 'duration');
         $hs_params_counter = 1;
         if (is_array($form->data($config->get('hs_price'), ''))) {
             $hs_params_counter = count($form->data($config->get('hs_price'), ''));
         }
         for ($i = 0; $i < $hs_params_counter; $i++) {
             foreach ($hs_params as $hs_param) {
                 $hs_param_value = $form->data($config->get('hs_' . $hs_param), '');
                 $checkout_values['li_' . $i . '_' . $hs_param] = is_array($hs_param_value) ? $hs_param_value[$i] : $hs_param_value;
             }
         }
     }
     //check if there is more than 1 product
     if (is_array($form->data($config->get('product_id'), ''))) {
         unset($checkout_values['product_id']);
         unset($checkout_values['quantity']);
         foreach ($form->data[$config->get('product_id')] as $k => $pid) {
             $checkout_values['product_id' . ($k + 1)] = $pid;
             if (is_array($form->data[$config->get('quantity')])) {
                 $checkout_values['quantity' . ($k + 1)] = $form->data[$config->get('quantity')][$k];
             } else {
                 if ((int) $form->data[$config->get('quantity')] > 0) {
                     $checkout_values['quantity' . ($k + 1)] = (int) $form->data[$config->get('quantity')];
                 } else {
                     $checkout_values['quantity' . ($k + 1)] = 1;
                 }
             }
         }
     }
     if ($config->get('extra_params')) {
         $extras = explode("\n", $config->get('extra_params'));
         foreach ($extras as $extra) {
             $values = array();
             $values = explode("=", $extra);
             $checkout_values[$values[0]] = $form->data[trim($values[1])];
         }
         $extras = \GCore\Libs\Str::list_to_array($config->get('extra_params', ''));
         foreach ($extras as $k => $v) {
             $checkout_values[$k] = $form->data($v, '');
         }
     }
     if ((bool) $settings->get('validated_2checkout', 0) === true) {
     } else {
         if ($config->get('parameter_set') == '2CO') {
         } else {
             if (isset($checkout_values['quantity'])) {
                 $checkout_values['quantity'] = rand(2, 5) * (int) $checkout_values['quantity'];
             } else {
                 $checkout_values['quantity1'] = rand(2, 5) * (int) $checkout_values['quantity1'];
             }
         }
     }
     $checkout_values = array_filter($checkout_values);
     $fields = "";
     foreach ($checkout_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     if ($config->get('routine', 'M') == 'M') {
         $url = 'https://www.2checkout.com/checkout/purchase?';
     } else {
         $url = 'https://www.2checkout.com/checkout/spurchase?';
     }
     if ($config->get('debug_only', 0) == 1) {
         echo $url . $fields;
     } else {
         \GCore\Libs\Env::redirect($url . $fields);
     }
 }
Beispiel #9
0
//$this->Toolbar->setTitle(l_('CF_LIST_DATA_TITLE'));
$this->Toolbar->addButton('remove', r_('index.php?ext=chronoforms&act=delete_data&table=' . $this->data['table']), l_('CF_DELETE'), $this->Assets->image('remove', 'toolbar/'), 'submit_selectors');
$this->Toolbar->addButton('backup', r_('index.php?ext=chronoforms&act=backup_data&table=' . $this->data['table']), l_('CF_BACKUP_TABLE'), \GCore\C::get('GCORE_ADMIN_URL') . 'extensions/chronoforms/assets/images/backup.png', 'link');
$this->Toolbar->addButton('cancel', r_('index.php?ext=chronoforms'), l_('CF_CANCEL'), $this->Assets->image('cancel', 'toolbar/'), 'link');
?>
<div class="row">
	<form action="<?php 
echo r_('index.php?ext=chronoforms&act=list_data&table=' . $this->data['table']);
?>
" method="post" name="admin_form" id="admin_form">
		<?php 
echo $this->DataTable->headerPanel($this->DataTable->_l('<h4>' . l_('CF_LIST_DATA_TITLE') . '</h4>') . $this->DataTable->_r($this->Toolbar->renderBar()));
$this->DataTable->create();
$columns = array('created' => l_('CF_CREATED'), 'id' => l_('CF_ID'));
if (!empty($form['Form']['extras']['db_fields_list'][$this->data['table']])) {
    $columns = \GCore\Libs\Str::list_to_array($form['Form']['extras']['db_fields_list'][$this->data['table']]);
}
$listing_header = array();
foreach ($columns as $column => $title) {
    $listing_header['ListData.' . $column] = $this->Sorter->link($title, 'ListData.' . $column);
}
$this->DataTable->header(array_merge(array('CHECK' => $this->Toolbar->selectAll()), $listing_header));
$listing_row = array();
$count = 0;
foreach ($columns as $column => $title) {
    $listing_row['ListData.' . $column] = array('style' => array('width' => '15%'));
    if (empty($count)) {
        $listing_row['ListData.' . $column]['link'] = r_('index.php?ext=chronoforms&act=show_data&table=' . $this->data['table'] . '&id={ListData.id}' . '&form_id=' . $this->data['form_id']);
    }
    $count++;
}
Beispiel #10
0
	public static function html_input($name, $params = array()){
		$output = '';

		$tags = array();
		switch($params['type']){
                        case 'input':
                                $params['type'] = $params['input_type'];
				$attributes = array('type', 'name', 'id', 'value', 'min', 'max', 'step', 'alt', 'src', 'class');
                                switch ($params['input_type']) {
                                        case 'number':
                                        case 'range': 
                                                $params['min'] = $params['number']['min'];
                                                $params['max'] = $params['number']['max'];
                                                $params['step'] = $params['number']['step'];
                                                break;
                                        case 'image': 
                                                $params['alt'] = $params['image']['alt'];
                                                $params['src'] = $params['image']['src'];
                                                break;
                                }
                                $tags[] = self::_concat($params, $attributes, '<input ', ' />');
                                break;
                        case 'number':
				$attributes = array('type', 'name', 'id', 'value', 'min', 'max', 'step', 'alt', 'class');
                                $tags[] = self::_concat($params, $attributes, '<input ', ' />');
                                break;
			case 'hidden':
				$attributes = array('type', 'name', 'id', 'value', 'alt', 'class');
				$tags[] = self::_concat($params, $attributes, '<input ', ' />');
				break;
			case 'submit':
			case 'button':
			case 'reset':
				$attributes = array('type', 'name', 'id', 'value', 'class', 'style', 'onclick');
				$tags[] = self::_concat($params, $attributes, '<input ', ' />');
				break;
			case 'textarea':
				$attributes = array('name', 'id', 'class', 'rows', 'cols', 'title', 'style', 'onclick', 'onchange', 'alt', 'placeholder', 'readonly');
				$tags[] = self::_concat($params, $attributes, '<textarea ', '>'.(isset($params['value']) ? $params['value'] : '').'</textarea>');
				break;
			case 'dropdown':
				$attributes = array('name', 'id', 'class', 'title', 'multiple', 'size', 'style', 'onclick', 'onchange', 'alt');
				if(array_key_exists('multiple', $params) AND empty($params['multiple'])){
					unset($params['multiple']);
				}
				$set_empty = false;
				if(array_key_exists('empty', $params) AND !empty($params['empty'])){
					$set_empty = true;
				}
				$tags[] = self::_concat($params, $attributes, '<select ', '>');
				if(!empty($params['options']) AND is_string($params['options']) AND strpos($params['options'], '=')){
					$params['options'] = \GCore\Libs\Str::list_to_array($params['options'], '=');
				}
				if(!empty($params['options']) AND is_array($params['options'])){
					if($set_empty){
						$params['options'] = array('' => $params['empty']) + $params['options'];
					}
					foreach($params['options'] as $value => $title){
						if(is_array($title)){
							//this is an optgroup
							$tags[] = self::_concat(array('label' => $value), array('value', 'label', 'class'), '<optgroup ', '>');
							foreach($title as $opt_v => $opt_l){
								$option_params = array('value' => $opt_v);
								if(isset($params['values']) AND in_array($opt_v, (array)$params['values'])){
									$option_params['selected'] = 'selected';
								}
								if(!empty($params['options_classes'][$opt_v])){
									$option_params['class'] = $params['options_classes'][$opt_v];
								}
								$tags[] = self::_concat($option_params, array('value', 'selected', 'class'), '<option ', '>'.$opt_l.'</option>');
							}
							$tags[] = '</optgroup>';
						}else{
							$option_params = array('value' => $value);
							if(isset($params['values']) AND in_array($value, (array)$params['values'])){
								$option_params['selected'] = 'selected';
							}
							if(!empty($params['options_classes'][$value])){
								$option_params['class'] = $params['options_classes'][$value];
							}
                                                        if (isset($params['empty_disable']) && $params['empty_disable'] === '1' && $option_params['value'] == ''){
                                                            $option_params['selected'] = 'selected';
                                                            $option_params['disabled'] = 'disabled';
                                                            $tags[] = self::_concat($option_params, array('value', 'selected', 'disabled', 'class'), '<option ', '>'.$title.'</option>');
                                                        } else {
                                                            $tags[] = self::_concat($option_params, array('value', 'selected', 'class'), '<option ', '>'.$title.'</option>');
                                                        }
						}
					}
				}
				$tags[] = '</select>';
				break;
			case 'radio':
				$attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
				if(!empty($params['ghost']) AND (bool)$params['ghost'] === true){
					$tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'].'_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
				}
				if(!empty($params['options']) AND is_array($params['options'])){
					$id = $params['id'].'__#';
					$originals = $params;
					foreach($params['options'] as $value => $label){
						unset($params['checked']);
						if(isset($originals['value']) AND strlen($originals['value']) AND $value == $originals['value']){
							$params['checked'] = 'checked';
						}
						$params['value'] = $value;
						$params['id'] = self::_field_uid($id);
						$item = array();
						$item[] = self::_concat($params, $attributes, '<input ', ' />');
						if(!empty($params['label_input'])){
							$label = array_pop($item).$label;
						}
						$item[] = self::label(array('text' => $label, 'class' => 'gcore-label', 'for' => $params['id']), $params);
						$tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-radio-item', 'id' => 'fitem__#'));
					}
					$params['id'] = '';
				}
				break;
			case 'checkbox_group':
				$attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
				if(!empty($params['ghost']) AND (bool)$params['ghost'] === true){
					$tags[] = self::input(str_replace('[]', '', $params['name']), array('type' => 'hidden', 'id' => $params['id'].'_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
				}
				$params['type'] = 'checkbox';
				if(!array_key_exists('brackets', $params) OR $params['brackets'] === true){
					$params['name'] = $params['name'].'[]';
				}
				if(!empty($params['options']) AND is_array($params['options'])){
					$id = $params['id'].'__#';
					foreach($params['options'] as $value => $label){
						unset($params['checked']);
						if(isset($params['values']) AND in_array($value, (array)$params['values'])){
							$params['checked'] = 'checked';
						}
						$params['value'] = $value;
						$params['id'] = self::_field_uid($id);
						$item = array();
						$item[] = self::_concat($params, $attributes, '<input ', ' />');
						if(!empty($params['label_input'])){
							$label = array_pop($item).$label;
						}
						$item[] = self::label(array('text' => $label, 'class' => 'gcore-label', 'for' => $params['id']), $params);
						$tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-checkbox-item', 'id' => 'fitem__#'));
					}
					$params['id'] = '';
				}
				break;
                        case 'tree_select': // Aqui: Willian Martins Costa
				$attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
				// Campo hidden (ghost)
                                if(!empty($params['ghost']) AND (bool)$params['ghost'] === true){
					$tags[] = self::input(str_replace('[]', '', $params['name']), array('type' => 'hidden', 'id' => $params['id'].'_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
				}
                                // Acrescentando colchetes ao nome, caso não haja
				if($params['min_select'] > 1 && !strpos($params['name'], '[]') !== false){
					$params['name'] = $params['name'].'[]';
				}
                                // Label
                                //$item[] = self::label(array('text' => $label, 'class' => 'gcore-label', 'for' => $params['id']), $params);
                                // Div que guarda as tags
                                $style = array(
                                    "background-color" => "#fff", "top" => "20px", "left" => "20px", "min-width" => "300px", "overflow" => "hidden", 
                                    "min-height" => "30px", "border" => "1px solid #CCC", "border-radius" => "4px", "padding" => "4px");
                                $item[] = self::container('div', '', array('id' => 'select_tags', 'style' => $style));
                                // input button limpar_selecionadas
                                $inp_limpar = array('type' => 'button', 'id' => 'clear', 'value' => 'Limpar Selecionadas');
                                $item[] = self::_concat($inp_limpar, array_keys($inp_limpar), '<input ', ' />');
                                // input button selecionar
                                $inp_selecionar = array('type' => 'button', 'id' => $params['id'], 'value' => 'Selecionar');
                                $item[] = self::_concat($inp_selecionar, array_keys($inp_selecionar), '<input ', ' />');
                                // Montando tudo
                                $tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-tree_select-item', 'id' => 'fitem__#'));
                                $tags[] = '<div id="modal_tree" style="display: none;"></div>';
				break;
			case 'checkbox':
				$attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
				if(!empty($params['ghost']) AND (bool)$params['ghost'] === true){
					$tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'].'_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
				}
				if(array_key_exists('checked', $params) AND empty($params['checked'])){
					unset($params['checked']);
				}
				if(array_key_exists('checked', $params) AND !empty($params['checked'])){
					$params['checked'] = 'checked';
				}
				if(array_key_exists('secondary_label', $params) AND !empty($params['secondary_label'])){
					$item = array();
					$item[] = self::_concat($params, $attributes, '<input ', ' />');
					$item[] = self::label(array('text' => $params['secondary_label'], 'class' => 'gcore-label', 'for' => $params['id']), $params);
					$tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-checkbox-item', 'id' => 'fitem__#'));
				}else{
					$tags[] = self::_concat($params, $attributes, '<input ', ' />');
				}
				break;
			case 'file':
				$attributes = array('type', 'name', 'id', 'class', 'title', 'style', 'onclick', 'onchange', 'alt', 'multiple');
				if(!empty($params['ghost']) AND (bool)$params['ghost'] === true){
					$tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'].'_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
				}
				if(!empty($params['multiple']) AND (bool)$params['multiple'] === true){
					$params['multiple'] = 'multiple';
				}else{
					if(isset($params['multiple'])){
						unset($params['multiple']);
					}
				}
				$tags[] = self::_concat($params, $attributes, '<input ', ' />');
				break;
			case 'multi':
				$layout = !empty($params['layout']) ? '-'.$params['layout'] : '';
				if(!empty($params['inputs'])){
					foreach($params['inputs'] as $sub_input){
						if(!empty($sub_input['name'])){
							//$tags[] = self::formInput($sub_input['name'], $sub_input, array('class' => 'gcore-subinput-container'.$layout, 'id' => 'fitem__#'));
							$sub_input['sub_input'] = true;
							$postfix = !empty($sub_input['id']) ? '-'.$sub_input['id'] : '__#';
							$generated_input = self::formInput($sub_input['name'], $sub_input, array('class' => 'gcore-subfield-container'.$layout, 'id' => 'fld'.$postfix));
							$tags[] = self::container('div', $generated_input, array('class' => 'gcore-subinput-container'.$layout, 'id' => 'fitem'.$postfix));
						}
					}
				}
				break;
			case 'custom':
				$tags[] = !empty($params['code']) ? $params['code'] : '';
				break;
                        case 'custom_text':
                                $params['type'] = 'text';
			case 'text':
			case 'password':
			default:
				$attributes = array('type', 'name', 'id', 'value', 'class', 'size', 'maxlength', 'title', 'style', 'onclick', 'onchange', 'alt', 'placeholder', 'readonly');
				$params['id'] = self::_field_uid($params['id']);
				//clear empty parameters if exists
				if(isset($params['size']) AND empty($params['size'])){
					unset($params['size']);
				}
				if(isset($params['maxlength']) AND empty($params['maxlength'])){
					unset($params['maxlength']);
				}
				$tags[] = self::_concat($params, $attributes, '<input ', ' />');
				break;
		}
		//self::$last_field_params = $params;
		$return = implode("\n", $tags);
		if(!empty($params['beforeInput'])){
                    $before =  (is_array($params['beforeInput']))?implode("\n", $params['beforeInput']):$params['beforeInput']; 
                    $return = $before.$return;
		}
		if(!empty($params['afterInput'])){
                    $after =  (is_array($params['afterInput']))?implode("\n", $params['afterInput']):$params['afterInput'];
                    $return = $return.$after;
		}
		return $return;
	}
Beispiel #11
0
 public static function html_input($name, $params = array())
 {
     $output = '';
     $tags = array();
     switch ($params['type']) {
         case 'hidden':
             $attributes = array('type', 'name', 'id', 'value', 'alt', 'class');
             $tags[] = self::_concat($params, $attributes, '<input ', ' />');
             break;
         case 'submit':
         case 'button':
         case 'reset':
             $attributes = array('type', 'name', 'id', 'value', 'class', 'style', 'onclick');
             $tags[] = self::_concat($params, $attributes, '<input ', ' />');
             break;
         case 'textarea':
             $attributes = array('name', 'id', 'class', 'rows', 'cols', 'title', 'style', 'onclick', 'onchange', 'alt', 'placeholder', 'readonly');
             $tags[] = self::_concat($params, $attributes, '<textarea ', '>' . (isset($params['value']) ? $params['value'] : '') . '</textarea>');
             break;
         case 'dropdown':
             $attributes = array('name', 'id', 'class', 'title', 'multiple', 'size', 'style', 'onclick', 'onchange', 'alt');
             if (array_key_exists('multiple', $params) and empty($params['multiple'])) {
                 unset($params['multiple']);
             }
             $set_empty = false;
             if (array_key_exists('empty', $params) and !empty($params['empty'])) {
                 $set_empty = true;
             }
             $tags[] = self::_concat($params, $attributes, '<select ', '>');
             if (!empty($params['options']) and is_string($params['options']) and strpos($params['options'], '=')) {
                 $params['options'] = \GCore\Libs\Str::list_to_array($params['options'], '=');
             }
             if (!empty($params['options']) and is_array($params['options'])) {
                 if ($set_empty) {
                     $params['options'] = array('' => $params['empty']) + $params['options'];
                 }
                 foreach ($params['options'] as $value => $title) {
                     if (is_array($title)) {
                         //this is an optgroup
                         $tags[] = self::_concat(array('label' => $value), array('value', 'label', 'class'), '<optgroup ', '>');
                         foreach ($title as $opt_v => $opt_l) {
                             $option_params = array('value' => $opt_v);
                             if (isset($params['values']) and in_array($opt_v, (array) $params['values'])) {
                                 $option_params['selected'] = 'selected';
                             }
                             if (!empty($params['options_classes'][$opt_v])) {
                                 $option_params['class'] = $params['options_classes'][$opt_v];
                             }
                             $tags[] = self::_concat($option_params, array('value', 'selected', 'class'), '<option ', '>' . $opt_l . '</option>');
                         }
                         $tags[] = '</optgroup>';
                     } else {
                         $option_params = array('value' => $value);
                         if (isset($params['values']) and in_array($value, (array) $params['values'])) {
                             $option_params['selected'] = 'selected';
                         }
                         if (!empty($params['options_classes'][$value])) {
                             $option_params['class'] = $params['options_classes'][$value];
                         }
                         $tags[] = self::_concat($option_params, array('value', 'selected', 'class'), '<option ', '>' . $title . '</option>');
                     }
                 }
             }
             $tags[] = '</select>';
             break;
         case 'radio':
             $attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
             if (!empty($params['ghost']) and (bool) $params['ghost'] === true) {
                 $tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'] . '_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
             }
             if (!empty($params['options']) and is_array($params['options'])) {
                 $id = $params['id'] . '__#';
                 $originals = $params;
                 foreach ($params['options'] as $value => $label) {
                     unset($params['checked']);
                     if (isset($originals['value']) and strlen($originals['value']) and $value == $originals['value']) {
                         $params['checked'] = 'checked';
                     }
                     $params['value'] = $value;
                     $params['id'] = self::_field_uid($id);
                     $item = array();
                     $item[] = self::_concat($params, $attributes, '<input ', ' />');
                     if (!empty($params['label_input'])) {
                         $label = array_pop($item) . $label;
                     }
                     $item[] = self::label(array('text' => $label, 'class' => 'gcore-label', 'for' => $params['id']), $params);
                     $tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-radio-item', 'id' => 'fitem__#'));
                 }
                 $params['id'] = '';
             }
             break;
         case 'checkbox_group':
             $attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
             if (!empty($params['ghost']) and (bool) $params['ghost'] === true) {
                 $tags[] = self::input(str_replace('[]', '', $params['name']), array('type' => 'hidden', 'id' => $params['id'] . '_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
             }
             $params['type'] = 'checkbox';
             if (!array_key_exists('brackets', $params) or $params['brackets'] === true) {
                 $params['name'] = $params['name'] . '[]';
             }
             if (!empty($params['options']) and is_array($params['options'])) {
                 $id = $params['id'] . '__#';
                 foreach ($params['options'] as $value => $label) {
                     unset($params['checked']);
                     if (isset($params['values']) and in_array($value, (array) $params['values'])) {
                         $params['checked'] = 'checked';
                     }
                     $params['value'] = $value;
                     $params['id'] = self::_field_uid($id);
                     $item = array();
                     $item[] = self::_concat($params, $attributes, '<input ', ' />');
                     if (!empty($params['label_input'])) {
                         $label = array_pop($item) . $label;
                     }
                     $item[] = self::label(array('text' => $label, 'class' => 'gcore-label', 'for' => $params['id']), $params);
                     $tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-checkbox-item', 'id' => 'fitem__#'));
                 }
                 $params['id'] = '';
             }
             break;
         case 'checkbox':
             $attributes = array('type', 'name', 'id', 'class', 'title', 'value', 'style', 'checked', 'onclick', 'onchange', 'alt');
             if (!empty($params['ghost']) and (bool) $params['ghost'] === true) {
                 $tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'] . '_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
             }
             if (array_key_exists('checked', $params) and empty($params['checked'])) {
                 unset($params['checked']);
             }
             if (array_key_exists('checked', $params) and !empty($params['checked'])) {
                 $params['checked'] = 'checked';
             }
             if (array_key_exists('secondary_label', $params) and !empty($params['secondary_label'])) {
                 $item = array();
                 $item[] = self::_concat($params, $attributes, '<input ', ' />');
                 $item[] = self::label(array('text' => $params['secondary_label'], 'class' => 'gcore-label', 'for' => $params['id']), $params);
                 $tags[] = self::container('div', implode("\n", $item), array('class' => 'gcore-checkbox-item', 'id' => 'fitem__#'));
             } else {
                 $tags[] = self::_concat($params, $attributes, '<input ', ' />');
             }
             break;
         case 'file':
             $attributes = array('type', 'name', 'id', 'class', 'title', 'style', 'onclick', 'onchange', 'alt', 'multiple');
             if (!empty($params['ghost']) and (bool) $params['ghost'] === true) {
                 $tags[] = self::input($params['name'], array('type' => 'hidden', 'id' => $params['id'] . '_ghost', ':data-ghost' => 1, 'value' => isset($params['ghost_value']) ? $params['ghost_value'] : ''));
             }
             if (!empty($params['multiple']) and (bool) $params['multiple'] === true) {
                 $params['multiple'] = 'multiple';
             } else {
                 if (isset($params['multiple'])) {
                     unset($params['multiple']);
                 }
             }
             $tags[] = self::_concat($params, $attributes, '<input ', ' />');
             break;
         case 'multi':
             $layout = !empty($params['layout']) ? '-' . $params['layout'] : '';
             if (!empty($params['inputs'])) {
                 foreach ($params['inputs'] as $sub_input) {
                     if (!empty($sub_input['name'])) {
                         //$tags[] = self::formInput($sub_input['name'], $sub_input, array('class' => 'gcore-subinput-container'.$layout, 'id' => 'fitem__#'));
                         $sub_input['sub_input'] = true;
                         $postfix = !empty($sub_input['id']) ? '-' . $sub_input['id'] : '__#';
                         $generated_input = self::formInput($sub_input['name'], $sub_input, array('class' => 'gcore-subfield-container' . $layout, 'id' => 'fld' . $postfix));
                         $tags[] = self::container('div', $generated_input, array('class' => 'gcore-subinput-container' . $layout, 'id' => 'fitem' . $postfix));
                     }
                 }
             }
             break;
         case 'custom':
             $tags[] = !empty($params['code']) ? $params['code'] : '';
             break;
         case 'text':
         case 'password':
         default:
             $attributes = array('type', 'name', 'id', 'value', 'class', 'size', 'maxlength', 'title', 'style', 'onclick', 'onchange', 'alt', 'placeholder', 'readonly');
             $params['id'] = self::_field_uid($params['id']);
             //clear empty parameters if exists
             if (isset($params['size']) and empty($params['size'])) {
                 unset($params['size']);
             }
             if (isset($params['maxlength']) and empty($params['maxlength'])) {
                 unset($params['maxlength']);
             }
             $tags[] = self::_concat($params, $attributes, '<input ', ' />');
             break;
     }
     //self::$last_field_params = $params;
     $return = implode("\n", $tags);
     if (!empty($params['beforeInput'])) {
         $return = $params['beforeInput'] . $return;
     }
     if (!empty($params['afterInput'])) {
         $return = $return . $params['afterInput'];
     }
     return $return;
 }
Beispiel #12
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     if (!$config->get('enabled')) {
         return;
     }
     $tablename = $config->get('tablename', '');
     $titles = array();
     $this->delimiter = $config->get('delimiter', ',');
     if ($config->get('columns', '')) {
         $columns = \GCore\Libs\Str::list_to_array($config->get('columns', ''));
         $titles = $columns;
         $columns = array_keys($columns);
     }
     if (!empty($tablename)) {
         \GCore\Libs\Model::generateModel('ListData', array('tablename' => $tablename));
         $list_model = '\\GCore\\Models\\ListData';
         if (!$config->get('columns', '')) {
             $columns = $list_model::getInstance()->dbo->getTableColumns($tablename);
             $titles = array_combine($columns, $columns);
         }
         if ($config->get('order_by', '')) {
             $order_by = array_map('trim', explode(',', $config->get('order_by', '')));
         } else {
             $order_by = $list_model::getInstance()->pkey;
         }
         $file_name = 'csv_export_' . $tablename . '_' . date('YmdHi') . '.csv';
         $rows = $list_model::getInstance()->find('all', array('fields' => $columns, 'order' => $order_by));
     } else {
         if (!$config->get('data_path', '')) {
             return;
         }
         $rows = \GCore\Libs\Arr::getVal($form->data, explode('.', $config->get('data_path', '')), array());
         $rows = array_values($rows);
         if (!$config->get('columns', '')) {
             $columns = array_keys($rows[0]);
             $titles = array_combine($columns, $columns);
         }
         $file_name = 'csv_export_' . date('YmdHis') . '.csv';
     }
     if ($config->get('excluded_columns', '')) {
         $excluded_columns = array_map('trim', explode("\n", $config->get('excluded_columns', '')));
         $columns = array_diff($columns, $excluded_columns);
     } else {
         $excluded_columns = array();
         //$columns;
     }
     header('Content-type: text/csv');
     header('Content-Disposition: attachment; filename=' . $file_name);
     header('Pragma: no-cache');
     header('Expires: 0');
     //$data = array($titles);
     foreach ($titles as $k => $v) {
         if (in_array($k, $columns)) {
             $data[0][$k] = $v;
         }
     }
     if (!empty($rows)) {
         foreach ($rows as $row) {
             $csv_data_row = array();
             if (!empty($tablename)) {
                 $row_path = $row['ListData'];
             } else {
                 $row_path = $row;
             }
             foreach ($row_path as $k => $v) {
                 if (in_array($k, $columns)) {
                     $csv_data_row[$k] = $v;
                 }
             }
             $data[] = $csv_data_row;
         }
     }
     @ob_end_clean();
     $this->outputCSV($data);
     exit;
 }