I have a Model Course with many relationship with timing. How do i update all the timings.
$course_Timeing = $course->courseTimings;
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator($this->request->getPost('date', 'string')), 'date');
$m->attachIterator(new ArrayIterator($this->request->getPost('timeFrom', 'string')), 'timeFrom');
$m->attachIterator(new ArrayIterator($this->request->getPost('timeTo', 'string')), 'timeTo');
$i = 0;
foreach ($m as $unit) {
//print_r($unit);
if (!empty($unit[0]) && !empty($unit[1]) && !empty($unit[2])) {
$course_Timeing = $course->courseTimings[$i];
$course_Timeing->assign(array(
//'course_id' => $course->id,
'date' => date('Y-m-d', strtotime($unit[0])),
'timeFrom' => date('H:i:s', strtotime($unit[1])),
'timeTo' => date('H:i:s', strtotime($unit[2])),
));
}
$i++;
}
$course->save does not save timings
Well i found a way out by
$course_Timeing = $course->courseTimings;
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator($this->request->getPost('date', 'string')), 'date');
$m->attachIterator(new ArrayIterator($this->request->getPost('timeFrom', 'string')), 'timeFrom');
$m->attachIterator(new ArrayIterator($this->request->getPost('timeTo', 'string')), 'timeTo');
$i = 0;
foreach ($m as $unit) {
//print_r($unit);
if (!empty($unit[0]) && !empty($unit[1]) && !empty($unit[2])) {
//$course_Timeing = $course->courseTimings[$i];
$course_Timeing[$i]->assign(array(
//'course_id' => $course->id,
'date' => date('Y-m-d', strtotime($unit[0])),
'timeFrom' => date('H:i:s', strtotime($unit[1])),
'timeTo' => date('H:i:s', strtotime($unit[2])),
));
if (!$course_Timeing[$i]->save()) {
foreach ($course_Timeing[$i]->getMessages() as $message) {
$this->flash->error($message);
}
}
}
$i++;
}
Related
Do you know how via a web page usind the IPB APi allowinfg to doynload a file. Until now I can the see the files but it's not possible to download it. My result myfile:zip.3313213213
Thank you
Below my approach :
public function getFilesInformations(int $id)
{
$curl = curl_init( $this->communityUrl . 'api/downloads/files?id=' . $id . '&download&perPage=300');
$array = [
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "{$this->apiKey}:",
CURLOPT_USERAGENT => "MyUserAgent/1.0"
];
curl_setopt_array( $curl, $array);
$response = curl_exec( $curl );
return $response;
}
My other function to get the file info
public function insertFilesInformations(int $id): bool
{
$json_result = $this->getFilesInformations($id);
$result = json_decode($json_result, true);
$i = 1;
if (is_array($result)) {
foreach ($result as $value) {
if (is_array($value)) {
foreach ($value as $file) {
$download = $file['files'][0]['url'];
var_dum($download);
}
}
}
}
return $download
}
the result is something like that : https://localhost/forum/uploads/monthly_2019_12/myfile_zip.a1fb44a2cb001aa6f3596ec4c6dfba16
I have some relations in my database but I can't handle relations data in DatabaseSeeder.php with factories.
This is my database schema.
I try with this code:
$categories = Category::factory()->count(3)->create();
$users = User::factory()->count(2)->create();
$products = collect();
$payment = array();
foreach ($users as $user) {
$payment = array_merge($payment, Payment::factory(4)->create([
'user_id' => $user->id,
])->toArray());
foreach ($categories as $category) {
$products->push(Product::factory()->state([
'user_id' => $user->id,
'category_id' => $category->id
]));
}
}
$prices = collect();
$first = true;
foreach ($products as $product) {
$prices->pull(Price::factory(2)->create([
'product_id' => $product->id,
'index' => $first
]));
$first = false;
}
But I got multiple errors. is there anyone to help me?
in code igniter a group of student details check in fore-each loop ,the student get by the bases of student admission number
my admission numbers are in $ad_no=$this->input->post('adn_no'); :-
array(5) { [0]=> string(5) "11784" [1]=> string(5) "11837" [2]=>
string(5) "11775" [3]=> string(5) "11937" [4]=> string(5) "12061" }
i try to select these admission numbers student, but the result show only first student result
.
my code:
foreach($ad_no as $key => $id) {
$this - > db - > where_in('ad_no', $id);
$query = $this - > db - > get('duration');
$r = $query - > result_array();
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this - > Daily_temp_model - > duration($durs);
using array push in foreach loop
$result=[];
foreach($ad_no as $key => $id) {
$this->db->where_in('ad_no', $id);
$query = $this-> db-> get('duration');
$r = $query-> result_array();
array_push($result, $r);
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this->Daily_temp_model->duration($durs);
using in_array
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>
If I do this http://www.website.com/index.php?page=search&sCategory=123&sFeed=rss
I can create a RSS feed for a particular category. But what if I want to create a RSS feed for several selected categories? is it possible? OSClass version is 3.3.2
I didnt find a short or integrated way to do it, so I coded it.
<?php
define('ABS_PATH', str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME']) . '/'));
if(PHP_SAPI==='cli') {
define('CLI', true);
}
require_once ABS_PATH . 'oc-load.php';
$mSearch = Search::newInstance();
$array_categorias = array("16","22","23","24","31","33","43","102","119","121","122","123","124");
$aItems = $mSearch->doCustomSearch($array_categorias);
View::newInstance()->_exportVariableToView('items', $aItems);
// FEED REQUESTED!
header('Content-type: text/xml; charset=utf-8');
$feed = new RSSFeed;
$feed->setTitle(__('Latest listings added') . ' - ' . osc_page_title());
$feed->setLink(osc_base_url());
$feed->setDescription(__('Latest listings added in') . ' ' . osc_page_title());
$contador_items = osc_count_items();
if(osc_count_items()>0) {
while(osc_has_items()) {
if(osc_count_item_resources() > 0){
osc_has_item_resources();
$feed->addItem(array(
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url(), ENT_COMPAT, "UTF-8" ),
'description' => osc_item_description(),
'dt_pub_date' => osc_item_pub_date(),
'image' => array( 'url' => htmlentities(osc_resource_thumbnail_url(), ENT_COMPAT, "UTF-8"),
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url() , ENT_COMPAT, "UTF-8") )
));
} else {
$feed->addItem(array(
'title' => osc_item_title(),
'link' => htmlentities( osc_item_url() , ENT_COMPAT, "UTF-8"),
'description' => osc_item_description(),
'dt_pub_date' => osc_item_pub_date()
));
}
}
}
$feed->dumpXML();
?>
I also had to add a couple of custom methods to the search model
public function _makeSQLCustomCategories($categories)
{
$cadena_select = DB_TABLE_PREFIX."t_item.*, ".DB_TABLE_PREFIX."t_item.s_contact_name as s_user_name,";
$cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_title, ";
$cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_description";
$this->dao->select($cadena_select);
$this->dao->from( DB_TABLE_PREFIX.'t_item' );
$this->dao->from( DB_TABLE_PREFIX. 't_item_description');
$this->dao->where(DB_TABLE_PREFIX. 't_item_description.fk_i_item_id = '. DB_TABLE_PREFIX. 't_item.pk_i_id');
//$this->dao->where(DB_TABLE_PREFIX. 't_item.b_premium = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_enabled = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_active = 1');
$this->dao->where(DB_TABLE_PREFIX. 't_item.b_spam = 0');
$where_categorias = "(";
$contador_categorias = 0;
$tamano_categories = sizeof($categories);
foreach ($categories as $categoria)
{
$contador = $contador + 1;
$where_categorias = $where_categorias. DB_TABLE_PREFIX. 't_item.fk_i_category_id = ' . $categoria ;
if ($contador == $tamano_categories)
break;
$where_categorias = $where_categorias . " OR ";
}
$where_categorias = $where_categorias . ")";
$this->dao->where($where_categorias );
$this->dao->groupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
$this->dao->orderBy(DB_TABLE_PREFIX. 't_item.pk_i_id', 'DESC');
$sql = $this->dao->_getSelect();
// reset dao attributes
$this->dao->_resetSelect();
return $sql;
}
public function doCustomSearch($categories, $extended = true, $count = true)
{
$sql = $this->_makeSQLCustomCategories($categories);
$result = $this->dao->query($sql);
if($count) {
$sql = $this->_makeSQLCustomCategories($categories);
$datatmp = $this->dao->query( $sql );
if( $datatmp == false ) {
$this->total_results = 0;
} else {
$this->total_results = $datatmp->numRows();
}
} else {
$this->total_results = 0;
}
if( $result == false ) {
return array();
}
if($result) {
$items = $result->result();
} else {
$items = array();
}
if($extended) {
return Item::newInstance()->extendData($items);
} else {
return $items;
}
}
I would like to add a variable to paypal payment form. Then I would like it to be added to the database . The variable is called "membre_id" (user ID) and is found in the $_SESSION['membre_id'].
Here's the code of form processing :
<?php
require 'lib/init.php';
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '');
if ( !empty($action) ) {
switch ( $action ) {
/***********************************************************************************************************************/
case 'paypal_ipn':
require ('lib/vendor/ipnlistener.php');
$listener = new IpnListener();
try {
$verified = $listener->processIpn();
if ( $verified ) {
// parse our custom field data
$custom = post('custom');
if ( $custom ) {
parse_str(post('custom'), $data);
} else {
$data = array();
}
// pull out some values
$payment_gross = post('payment_gross');
$item_name = post('item_name');
// build customer data
$name = isset($data['name']) && $data['name'] ? $data['name'] : null;
$name_arr = explode(' ', trim($name));
$first_name = $name_arr[0];
$last_name = trim(str_replace($first_name, '', $name));
$email = isset($data['email']) && $data['email'] ? $data['email'] : null;
$description = $item_name ? $item_name : 'no description entered';
$address = isset($data['address']) && $data['address'] ? $data['address'] : null;
$city = isset($data['city']) && $data['city'] ? $data['city'] : null;
$state = isset($data['state']) && $data['state'] ? $data['state'] : null;
$zip = isset($data['zip']) && $data['zip'] ? $data['zip'] : null;
$country = isset($data['country']) && $data['country'] ? $data['country'] : null;
// check for invoice first
if ( isset($data['invoice_id']) && $data['invoice_id'] ) {
$invoice = Model::factory('Invoice')->find_one($data['invoice_id']);
$amount = $invoice->amount;
$type = 'invoice';
$description = $invoice->description;
// now check for item
} elseif ( isset($data['item_id']) && $data['item_id'] ) {
$item = Model::factory('Item')->find_one($data['item_id']);
$amount = $item->price;
$type = 'item';
// check for input amount
} elseif ( $payment_gross ) {
$amount = $payment_gross;
$type = 'input';
// return error if none found
} else {
$amount = 0;
$type = '';
}
switch ( post('txn_type') ) {
case 'web_accept':
// save payment record
$payment = Model::factory('Payment')->create();
$payment->invoice_id = isset($invoice) ? $invoice->id : null;
$payment->name = $name;
$payment->email = $email;
$payment->amount = $amount;
$payment->description = isset($item) ? $item->name : $description;
$payment->address = $address;
$payment->city = $city;
$payment->state = $state;
$payment->zip = $zip;
$payment->country = $country;
$payment->type = $type;
$payment->paypal_transaction_id = post('txn_id');
$payment->save();
// update paid invoice
if ( isset($invoice) ) {
$invoice->status = 'Paid';
$invoice->date_paid = date('Y-m-d H:i:s');
$invoice->save();
}
// build email values first
$values = array(
'customer_name' => $payment->name,
'customer_email' => $payment->email,
'amount' => currency($payment->amount) . '<small>' . currencySuffix() . '</small>',
'description_title' => isset($item) ? 'Item' : 'Description',
'description' => $payment->description,
'payment_method' => 'PayPal',
'transaction_id' => $payment->paypal_transaction_id,
'url' => url(''),
);
email($config['email'], 'payment-confirmation-admin', $values, 'You\'ve received a new payment!');
email($payment->email, 'payment-confirmation-customer', $values, 'Thank you for your payment to ' . $config['name']);
break;
case 'subscr_signup':
try {
$unique_subscription_id = uniqid();
// save subscription record
$subscription = Model::factory('Subscription')->create();
$subscription->unique_id = $unique_subscription_id;
$subscription->paypal_subscription_id = post('subscr_id');
$subscription->name = $name;
$subscription->email = $email;
$subscription->address = $address;
$subscription->city = $city;
$subscription->state = $state;
$subscription->zip = $zip;
$subscription->country = $country;
$subscription->description = isset($item) ? $item->name : $description;
$subscription->price = post('amount3');
$subscription->billing_day = date('j', strtotime(post('subscr_date')));
$subscription->length = $config['subscription_length'];
$subscription->interval = $config['subscription_interval'];
$subscription->trial_days = $config['enable_trial'] ? $config['trial_days'] : null;
$subscription->status = 'Active';
$subscription->date_trial_ends = $config['enable_trial'] ? date('Y-m-d', strtotime('+' . $config['trial_days'] . ' days')) : null;
$subscription->save();
$trial = $subscription->date_trial_ends ? ' <span style="color:#999999;font-size:16px">(Billing starts after your ' . $config['trial_days'] . ' day free trial ends)</span>' : '';
$values = array(
'customer_name' => $name,
'customer_email' => $email,
'amount' => currency(post('amount3')) . '<small>' . currencySuffix() . '</small>' . $trial,
'description_title' => isset($item) ? 'Item' : 'Description',
'description' => isset($item) ? $item->name : $description,
'payment_method' => 'PayPal',
'subscription_id' => $subscription->paypal_subscription_id,
'manage_url' => url('manage.php?subscription_id=' . $unique_subscription_id)
);
email($config['email'], 'subscription-confirmation-admin', $values, 'You\'ve received a new recurring payment!');
email($email, 'subscription-confirmation-customer', $values, 'Thank you for your recurring payment to ' . $config['name']);
} catch (Exception $e) {
}
break;
case 'subscr_cancel':
$subscription = Model::factory('Subscription')->where('paypal_subscription_id', post('subscr_id'))->find_one();
if ( $subscription ) {
$subscription->status = 'Canceled';
$subscription->date_canceled = date('Y-m-d H:i:s');
$subscription->save();
// send subscription cancelation email now
$values = array(
'customer_name' => $subscription->name,
'customer_email' => $subscription->email,
'amount' => currency($subscription->price) . '<small>' . currencySuffix() . '</small>',
'description' => $subscription->description,
'payment_method' => 'PayPal',
'subscription_id' => $subscription->paypal_subscription_id
);
email($config['email'], 'subscription-canceled-admin', $values, 'A recurring payment has been canceled.');
email($subscription->email, 'subscription-canceled-customer', $values, 'Your recurring payment to ' . $config['name'] . ' has been canceled.');
}
break;
case 'subscr_eot':
$subscription = Model::factory('Subscription')->where('paypal_subscription_id', post('subscr_id'))->find_one();
if ( $subscription && $subscription->status == 'Active' ) {
$subscription->status = 'Expired';
$subscription->date_canceled = null;
$subscription->save();
}
break;
}
} else {
die();
}
} catch (Exception $e) {
die();
}
break;
/***********************************************************************************************************************/
case 'paypal_success':
go('index.php#status=paypal_success');
break;
/***********************************************************************************************************************/
case 'paypal_subscription_success':
go('index.php#status=paypal_subscription_success');
break;
/***********************************************************************************************************************/
case 'paypal_cancel':
msg('You canceled your PayPal payment, no payment has been made.', 'warning');
go('index.php');
break;
/***********************************************************************************************************************/
case 'delete_payment':
if ( isset($_GET['id']) ) {
$payment = Model::factory('Payment')->find_one($_GET['id']);
$payment->delete();
}
msg('Payment has been deleted successfully.', 'success');
go('admin.php#tab=payments');
break;
/***********************************************************************************************************************/
case 'delete_subscription':
if ( isset($_GET['id']) ) {
$subscription = Model::factory('Subscription')->find_one($_GET['id']);
$subscription->delete();
}
msg('Subscription has been deleted successfully.', 'success');
go('admin.php#tab=subscriptions');
break;
/***********************************************************************************************************************/
case 'create_invoice':
if ( post('email') && post('amount') && post('description') ) {
$unique_invoice_id = uniqid();
$invoice = Model::factory('Invoice')->create();
$invoice->unique_id = $unique_invoice_id;
$invoice->email = post('email');
$invoice->description = post('description');
$invoice->amount = post('amount');
$invoice->number = post('number');
$invoice->status = 'Unpaid';
$invoice->date_due = post('date_due') ? date('Y-m-d', strtotime(post('date_due'))) : null;
$invoice->save();
}
$number = $invoice->number ? $invoice->number : $invoice->id();
if ( post('send_email') && post('send_email') ) {
$values = array(
'number' => $number,
'amount' => currency($invoice->amount) . '<small>' . currencySuffix() . '</small>',
'description' => $invoice->description,
'date_due' => !is_null($invoice->date_due) ? date('F jS, Y', strtotime($invoice->date_due)) : '<em>no due date set</em>',
'url' => url('?invoice_id=' . $unique_invoice_id)
);
email($invoice->email, 'invoice', $values, 'Invoice from ' . $config['name']);
$msg = ' and sent';
}
msg('Invoice has been created' . (isset($msg) ? $msg : '') . ' successfully.', 'success');
go('admin.php#tab=invoices');
break;
/***********************************************************************************************************************/
case 'delete_invoice':
if ( isset($_GET['id']) ) {
$invoice = Model::factory('Invoice')->find_one($_GET['id']);
$invoice->delete();
}
msg('Invoice has been deleted successfully.', 'success');
go('admin.php#tab=invoices');
break;
/***********************************************************************************************************************/
case 'add_item':
if ( post('name') && post('price') ) {
$item = Model::factory('Item')->create();
$item->name = post('name');
$item->price = post('price');
$item->save();
}
msg('Item has been added successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'edit_item':
if ( post('id') && post('name') && post('price') ) {
$item = Model::factory('Item')->find_one(post('id'));
$item->name = post('name');
$item->price = post('price');
$item->save();
}
msg('Item has been edited successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'delete_item':
if ( isset($_GET['id']) ) {
$item = Model::factory('Item')->find_one($_GET['id']);
$item->delete();
}
msg('Item has been deleted successfully.', 'success');
go('admin.php#tab=items');
break;
/***********************************************************************************************************************/
case 'save_config':
if ( post('config') && is_array(post('config')) ) {
foreach ( post('config') as $key => $value ) {
$config = Model::factory('Config')->where('key', $key)->find_one();
if ( $config ) {
$config->value = $value;
$config->save();
}
}
}
msg('Your settings have been saved successfully.', 'success');
go('admin.php#tab=settings');
break;
/***********************************************************************************************************************/
case 'login':
if (
post('admin_username') && post('admin_username') == $config['admin_username'] &&
post('admin_password') && post('admin_password') == $config['admin_password']
) {
// login successful, set session
$_SESSION['admin_username'] = $config['admin_username'];
} else {
// login failed, set error message
msg('Login attempt failed, please try again.', 'danger');
}
go('admin.php');
break;
/***********************************************************************************************************************/
case 'logout':
unset($_SESSION['admin_username']);
session_destroy();
session_start();
msg('You have been logged out successfully.', 'success');
go('admin.php');
break;
/***********************************************************************************************************************/
case 'install':
$status = true;
$message = '';
try {
$db = new PDO('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name'], $config['db_username'], $config['db_password']);
$sql = file_get_contents('lib/sql/install.sql');
$result = $db->exec($sql);
} catch (PDOException $e) {
$status = false;
$message = $e->getMessage();
}
$response = array(
'status' => $status,
'message' => $message
);
header('Content-Type: application/json');
die(json_encode($response));
break;
/***********************************************************************************************************************/
}
}
There is a parameter in the API request called "custom". That's what you need to pass your data in and then it will come back within IPN as $_POST['custom']