diff --git a/api/v2/get/dealers.php b/api/v2/get/dealers.php new file mode 100644 index 0000000..74c71a4 --- /dev/null +++ b/api/v2/get/dealers.php @@ -0,0 +1,105 @@ +soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} + +//default whereclause +list($whereclause,$condition) = getWhereclauselvl2("",$permission,$partner,'get'); + +//NEW ARRAY +$criterias = []; +$clause = ''; + +//Check for $_GET variables and build up clause +if(isset($get_content) && $get_content!=''){ + //GET VARIABLES FROM URL + $requests = explode("&", $get_content); + //Check for keys and values + foreach ($requests as $y){ + $v = explode("=", $y); + //INCLUDE VARIABLES IN ARRAY + $criterias[$v[0]] = $v[1]; + + if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){ + //do nothing + } + elseif ($v[0] == 'search') { + //build up search + $clause .= ' AND name like :'.$v[0]; + } + else {//create clause + $clause .= ' AND d.'.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} + +//Define Query +if(isset($criterias['totals']) && $criterias['totals'] ==''){ +//Request for total rows + $sql = 'SELECT count(*) as count FROM dealers '.$whereclause.''; +} +else { + //SQL for Paging + $sql = 'SELECT * FROM dealers '.$whereclause.' LIMIT :page,:num_products'; +} +$stmt = $pdo->prepare($sql); + +//Bind to query +if (str_contains($whereclause, ':condition')){ + $stmt->bindValue('condition', $condition, PDO::PARAM_STR); +} + +if (!empty($criterias)){ + foreach ($criterias as $key => $value){ + $key_condition = ':'.$key; + if (str_contains($whereclause, $key_condition)){ + if ($key == 'search'){ + $search_value = '%'.$value.'%'; + $stmt->bindValue($key, $search_value, PDO::PARAM_STR); + } + else { + $stmt->bindValue($key, $value, PDO::PARAM_STR); + } + } + } +} + +//Add paging details +if(isset($criterias['totals']) && $criterias['totals']==''){ + $stmt->execute(); + $messages = $stmt->fetch(); + $messages = $messages[0]; +} +else { + $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; + $stmt->bindValue('page', ($current_page - 1) * $page_rows_dealers, PDO::PARAM_INT); + $stmt->bindValue('num_products', $page_rows_dealers, PDO::PARAM_INT); + + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +//------------------------------------------ +//JSON_ENCODE +//------------------------------------------ +$messages = json_encode($messages, JSON_UNESCAPED_UNICODE); + +//Send results +echo $messages; + +?> \ No newline at end of file diff --git a/api/v2/post/dealers.php b/api/v2/post/dealers.php new file mode 100644 index 0000000..d06fbd0 --- /dev/null +++ b/api/v2/post/dealers.php @@ -0,0 +1,87 @@ +soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} + +//default whereclause +list($whereclause,$condition) = getWhereclause('',$permission,$partner,''); + + +//BUILD UP PARTNERHIERARCHY FROM USER +$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); + +$id = $post_content['rowID'] ?? ''; //check for rowID +$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT +if (isset($post_content['delete'])){$command = 'delete';} //change command to delete + +//CREATE EMPTY STRINGS +$clause = ''; +$clause_insert =''; +$input_insert = ''; + + +if ($command == 'update'){ + $post_content['updatedby'] = $username ; +} +if ($command == 'insert'){ + $post_content['createdby'] = $username; + $post_content['accounthierarchy'] = $partner_product; +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } +} + +//CLEAN UP INPUT +$clause = substr($clause, 2); //Clean clause - remove first comma +$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma +$input_insert = substr($input_insert, 1); //Clean clause - remove first comma + +//QUERY AND VERIFY ALLOWED +if ($command == 'update' && isAllowed('dealers',$profile,$permission,'U') === 1){ + $sql = 'UPDATE dealers SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('dealers',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO dealers ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('dealers',$profile,$permission,'D') === 1){ + $sql = 'DELETE FROM dealers WHERE rowID = ? '.$whereclause; + $stmt = $pdo->prepare($sql); + $stmt->execute([$id]); + + //Add deletion to changelog + changelog($dbname,'dealers',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + + +?> \ No newline at end of file diff --git a/custom/soveliti/settings/settingsmenu.php b/custom/soveliti/settings/settingsmenu.php index 458e558..f9b00eb 100644 --- a/custom/soveliti/settings/settingsmenu.php +++ b/custom/soveliti/settings/settingsmenu.php @@ -54,6 +54,14 @@ $main_menu = [ "name" => "menu_identity" ] ], + "dealers" => [ + "main_menu" => [ + "url" => "dealers", + "selected" => "dealers", + "icon" => "fas fa-tachometer-alt", + "name" => "menu_dealers" + ] + ], "buildtool" => [ "main_menu" => [ "url" => "buildtool", @@ -307,6 +315,8 @@ $page_rows_discounts = 25;//discounts $page_rows_shipping = 25;//discounts $page_rows_transactions = 25; //transactions $page_rows_invoice = 25; //invoices +$page_rows_dealers = 25; //dealers + //------------------------------------------ // Languages supported //------------------------------------------ diff --git a/dealers.php b/dealers.php new file mode 100644 index 0000000..0a3a4a7 --- /dev/null +++ b/dealers.php @@ -0,0 +1,142 @@ + +
+ +
+

'.($dealers_h2 ?? 'dealers').' ('.$query_total.')

+

'.($dealers_p ?? '').'

+
+
+'; + +if (isset($success_msg)){ +$view .= '
+ +

'.$success_msg.'

+ +
'; +} + +$view .= ' +
+ '.($button_create_dealers ?? 'Create dealer').' +
+
+
+ + + + + + + + + + + '; + if (empty($dealers)){ + $view .= ' + + '; + } + else { + foreach ($dealers as $order){ + + //Translate status INT to STR + $payment_status = 'general_status_'.$dealer['status']; + + $view .= ' + + + + + + + '; + } + } + +$view .= ' + +
'.($dealers_id ?? '#').''.($dealers_status ?? 'status').''.($dealers_name ?? 'Name').''.($dealers_created ?? 'Created').''.$general_actions.'
'.($message_no_dealers ?? 'There are no dealers').'
'.$dealer['id'].''.(${$dealer_status} ?? $dealer['status']).''.$dealer['name'].''.getRelativeTime($dealer['created']).''.$general_view.'
+
+
+'; + +$view.=''; +//OUTPUT +echo $view; + +template_footer(); +?> \ No newline at end of file diff --git a/settings/settingsmenu.php b/settings/settingsmenu.php index 458e558..f9b00eb 100644 --- a/settings/settingsmenu.php +++ b/settings/settingsmenu.php @@ -54,6 +54,14 @@ $main_menu = [ "name" => "menu_identity" ] ], + "dealers" => [ + "main_menu" => [ + "url" => "dealers", + "selected" => "dealers", + "icon" => "fas fa-tachometer-alt", + "name" => "menu_dealers" + ] + ], "buildtool" => [ "main_menu" => [ "url" => "buildtool", @@ -307,6 +315,8 @@ $page_rows_discounts = 25;//discounts $page_rows_shipping = 25;//discounts $page_rows_transactions = 25; //transactions $page_rows_invoice = 25; //invoices +$page_rows_dealers = 25; //dealers + //------------------------------------------ // Languages supported //------------------------------------------ diff --git a/settings/settingsviews.php b/settings/settingsviews.php index 648dded..16b891b 100644 --- a/settings/settingsviews.php +++ b/settings/settingsviews.php @@ -17,6 +17,9 @@ $all_views = [ "cartests", "cartest", "cartest_manage", + "dealers", + "dealer", + "dealer_manage", "assets", "equipments", "equipment", diff --git a/uploader.php b/uploader.php index b06cdfc..7d1916e 100644 --- a/uploader.php +++ b/uploader.php @@ -13,75 +13,85 @@ $delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'], $create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C'); if ($create_allowed === 1 && $_POST){ - + $log_results = []; - foreach ($_POST as $contents){ + $tableName = json_decode($_POST['table'],true); + $contents = json_decode($_POST['data'],true); - $contents = json_decode($contents,true); - - foreach ($contents as $content){ + foreach ($contents as $content){ - //CHECK IF VARIABLE EXISTS - $text_variable = ioServer('/v2/translations/variable='.$content['variable'],''); - if (!empty($text_variable)){$text_variable = json_decode($text_variable,true);}else{$text_variable = null;} + switch ($tableName) { - //IF NO ERRORS PROCES IT - if (is_array($text_variable)){ + case 'text_variables': + //CHECK IF VARIABLE EXISTS + $text_variable = ioServer('/v2/translations/variable='.$content['variable'],''); + if (!empty($text_variable)){$text_variable = json_decode($text_variable,true);}else{$text_variable = null;} - if (count($text_variable) == 0){ - //VARIABLE NOT FOUND -> CREATE - $payload = json_encode(array("variable" => $content['variable']), JSON_UNESCAPED_UNICODE); - //API call - $text_variable_new = ioServer('/v2/translations',$payload); - //returns results - $text_variable_new = json_decode($text_variable_new ,true); - //Provide feedback - $log_results[$content['variable']]['rowID'] = $text_variable_new['rowID'].' created'; - } + //IF NO ERRORS PROCES IT + if (is_array($text_variable)){ - $text_variable = $text_variable[0] ?? 'new'; - //VARIABLE ROWID - $text_variable_rowid = ($text_variable != 'new') ? $text_variable['rowID'] : $text_variable_new['rowID']; - - foreach ($content as $key => $var){ + if (count($text_variable) == 0){ + //VARIABLE NOT FOUND -> CREATE + $payload = json_encode(array("variable" => $content['variable']), JSON_UNESCAPED_UNICODE); + //API call + $text_variable_new = ioServer('/v2/translations',$payload); + //returns results + $text_variable_new = json_decode($text_variable_new ,true); + //Provide feedback + $log_results[$content['variable']]['rowID'] = $text_variable_new['rowID'].' created'; + } + + $text_variable = $text_variable[0] ?? 'new'; + //VARIABLE ROWID + $text_variable_rowid = ($text_variable != 'new') ? $text_variable['rowID'] : $text_variable_new['rowID']; - if ($var != $content['variable']){ - $language_key = strtoupper($key); + foreach ($content as $key => $var){ + + if ($var != $content['variable']){ + $language_key = strtoupper($key); - //check if variable_id and language_key combination already exists - $text_translation = ioServer('/v2/translations_details/variable_ID='.$text_variable_rowid.'&language_key='.$language_key,''); - if (!empty($text_translation)){$text_translation = json_decode($text_translation,true);}else{$text_translation = null;} - - - if (count($text_translation) == 0){ - //TRANSLATION NOT FOUND ->CREATE - $payload = json_encode(array("variable_ID" => $text_variable_rowid, "language_key" => $language_key, "translation" => $var), JSON_UNESCAPED_UNICODE); - $text_translation_new = ioServer('/v2/translations_details',$payload); - $text_translation_new = json_decode($text_translation_new ,true); - //Provide feedback - $log_results[$content['variable']][$language_key] = $text_translation_new['rowID'].' created'; - } - elseif(count($text_translation) > 0){ + //check if variable_id and language_key combination already exists + $text_translation = ioServer('/v2/translations_details/variable_ID='.$text_variable_rowid.'&language_key='.$language_key,''); + if (!empty($text_translation)){$text_translation = json_decode($text_translation,true);}else{$text_translation = null;} - $text_translation = $text_translation[0]; - //TRANSLATION FOUND -> UPDATE - $payload = json_encode(array("rowID" => $text_translation['rowID'] , "translation" => $var), JSON_UNESCAPED_UNICODE); - $text_translation = ioServer('/v2/translations_details',$payload); - $text_translation = json_decode($text_translation ,true); - //Provide feedback - $log_results[$content['variable']][$language_key] = $text_translation['rowID'].' updated'; + + if (count($text_translation) == 0){ + //TRANSLATION NOT FOUND ->CREATE + $payload = json_encode(array("variable_ID" => $text_variable_rowid, "language_key" => $language_key, "translation" => $var), JSON_UNESCAPED_UNICODE); + $text_translation_new = ioServer('/v2/translations_details',$payload); + $text_translation_new = json_decode($text_translation_new ,true); + //Provide feedback + $log_results[$content['variable']][$language_key] = $text_translation_new['rowID'].' created'; + } + elseif(count($text_translation) > 0){ + + $text_translation = $text_translation[0]; + //TRANSLATION FOUND -> UPDATE + $payload = json_encode(array("rowID" => $text_translation['rowID'] , "translation" => $var), JSON_UNESCAPED_UNICODE); + $text_translation_update = ioServer('/v2/translations_details',$payload); + $text_translation_update = json_decode($text_translation_update ,true); + //Provide feedback + $log_results[$content['variable']][$language_key] = $text_translation['rowID'].' updated'; + + } else { + $log_results[$content['variable']][$language_key] = 'not updated'; + } - } else { - $log_results[$content['variable']][$language_key] = 'not updated'; } - } + } else { + $log_results[$content['variable']] = 'error'; } - } else { - $log_results[$content['variable']] = 'error'; - } + break; + + case 'dealers': + + + break; } + } + print_r($log_results); return $log_results; } @@ -177,6 +187,10 @@ $view ='