اذهب إلى المحتوى

mohammadgholeh

الأعضاء
  • المساهمات

    6
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة mohammadgholeh

  1. السلام عليكم

    استخدم سكربت Mysqli CRUD - Data Management System 

    طريقة عمل السكربت عند اضافة سجل جديد من خلال form لا يتم اضافته مباشرة الى قاعدة البيانات بل يوجد شاشة confirm.

    أريد حذف شاشة confirm لكن validation  على form مربوط بشاشة confirm h.

    كيف أحذف شاشة confirm مع الاحتفاظ بvalidation  على form؟

    رابط السكربت اونلاين

    الكود المسؤول عن ذلك:

    switch ($this->action) {
    			case 'copy_confirm' :
    			case 'form_confirm' :
    				$saveOnclick = "$('#action_type').val('save'); $('#".$this->uid."').submit();";
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn btn-success',
    						'onclick' => $saveOnclick
    				), btn_save ) );
    				$backOnclick = "$('#action_type').val('back'); $('#".$this->uid."').submit();";
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn ',
    						'onclick' => $backOnclick
    				), btn_back ) );
    				$fieldset->addChildren ( $controlGroup );
    				break;
    			case 'view' :
    				$queryString [$this->actionKey] = 'index';
    				if (isset ( $queryString ['key'] )) {
    					unset ( $queryString ['key'] );
    				}
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn ',
    						'href' => '?' . http_build_query ( $queryString, '', '&' )
    				), btn_cancel ) );
    				$fieldset->addChildren ( $controlGroup );
    				break;
    			case 'delete' :
    				$deleteOnclick = "$('#action_type').val('delete'); $('#".$this->uid."').submit();";
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn btn-danger',
    						'onclick' => $deleteOnclick
    				), btn_delete ) );
    				$queryString [$this->actionKey] = 'index';
    				if (isset ( $queryString ['key'] )) {
    					unset ( $queryString ['key'] );
    				}
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn ',
    						'href' => '?' . http_build_query ( $queryString, '', '&' )
    				), btn_cancel ) );
    				$fieldset->addChildren ( $controlGroup );
    				break;
    			case 'form' :
    			default :
    				$confirmOnclick = "$('#action_type').val('confirm'); $('#".$this->uid."').submit();";
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn btn-success',
    						'onclick' => $confirmOnclick
    				), btn_confirm ) );
    				$queryString [$this->actionKey] = 'index';
    				if (isset ( $queryString ['key'] )) {
    					unset ( $queryString ['key'] );
    				}
    				$fa->addChildren ( new HtmlTag ( 'a', array (
    						'class' => 'btn',
    						'href' => '?' . http_build_query ( $queryString, '', '&' )
    				), btn_cancel ) );
    				$fieldset->addChildren ( $controlGroup );
    				break;
    		}

    ثم هذا الكود 

    if (! empty ( $_POST ) && $_POST ['token'] == $_SESSION [$this->uid] [$_POST ['token_key']] && $this->uid . "_auth_token" . '_' . md5 ( $tokenId ) == $_POST ['token_key']) {
    			switch ($_POST ['action_type']) {
    				case 'confirm' :
    					$error = $this->dataProcessing ();
    					if (! empty ( $error )) {
    						$errors ['data_processing'] = $error;
    					}
    					$action = $this->action . '_confirm';
    					if (! empty ( $this->validates )) {
    						if (! class_exists ( 'AbstractValidator' )) {
    							require dirname ( __FILE__ ) . '/validation/AbstractValidator.php';
    						}
    						if (! class_exists ( 'FormValidator' )) {
    							require dirname ( __FILE__ ) . '/validation/FormValidator.php';
    						}
    
    						$formValidator = new FormValidator ();
    						foreach ( $this->validates as $field => $args ) {
    							$type = $args [1];
    							$aryType = explode ( '_', $type );
    							$class = '';
    							if (! empty ( $aryType )) {
    								foreach ( $aryType as $t ) {
    									if (! empty ( $t )) {
    										$class .= ucfirst ( strtolower ( $t ) );
    									}
    								}
    							}
    							$class .= 'Validator';
    
    							if (! class_exists ( $class )) {
    								require dirname ( __FILE__ ) . '/validation/' . $class . '.php';
    							}
    							$hidden = new InputHiddenTag ( array (
    									'name' => $this->uid . '.' . $field
    							) );
    							if (isset ( $this->alias [$field] )) {
    								$name = $this->alias [$field];
    							} else {
    								$name = '';
    								$tmp = explode ( '.', $field );
    								foreach ( $tmp as $t ) {
    									$name .= ucfirst ( $t );
    								}
    							}
    							$validator = new $class ( $field, $name, $hidden->getValue () );
    							if (method_exists ( $validator, 'init' )) {
    								$validator->init ( $args );
    							}
    							$formValidator->addValidator ( $validator );
    						}
    						if (! $formValidator->validate ()) {
    							$errors = array_merge ( $errors, $formValidator->errors );
    							$action = $this->action;
    						}
    					}
    					break;
    				case 'save' :
    					$editFlag = true;
    
    					if (! empty ( $this->primaryKeys )) {
    						foreach ( $this->primaryKeys as $k3 => $v3 ) {
    							foreach ( $v3 as $v4 ) {
    								if ($k3 == $this->table) {
    									if (empty ( $_POST [$this->uid] [$k3] [$v4] ) || trim ( $_POST [$this->uid] [$k3] [$v4] ) == '') {
    										$editFlag = false;
    										break;
    									}
    								}
    							}
    							if ($editFlag == false) {
    								break;
    							}
    						}
    					}
    					$queryString = $this->queryString;
    					$queryString [$this->actionKey] = 'index';
    					if (isset ( $queryString ['key'] )) {
    						unset ( $queryString ['key'] );
    					}
    					$req = $this->getData ();
    
    					if ($editFlag == false) {
    						if (! empty ( $this->callback ['BEFORE_INSERT'] )) {
    							foreach ( $this->callback ['BEFORE_INSERT'] as $callback ) {
    								if (isset ( $callback [1] ) && file_exists ( $callback [1] )) {
    									require_once $callback [1];
    								}
    								if (is_callable ( $callback [0] )) {
    									$req = call_user_func ( $callback [0], $this, $req );
    								}
    							}
    						}
    
    						$this->insert ( $req, $this->table );
    
    						if (! empty ( $this->callback ['AFTER_INSERT'] )) {
    							foreach ( $this->callback ['AFTER_INSERT'] as $callback ) {
    								if (isset ( $callback [1] ) && file_exists ( $callback [1] )) {
    									require_once $callback [1];
    								}
    								if (is_callable ( $callback [0] )) {
    									call_user_func ( $callback [0], $this, $req, $this->insetId );
    								}
    							}
    						}
    						$this->redirect ( "?" . http_build_query ( $queryString, '', '&' ) );
    					} else {
    						if (! empty ( $this->callback ['BEFORE_UPDATE'] )) {
    							foreach ( $this->callback ['BEFORE_UPDATE'] as $callback ) {
    								if (isset ( $callback [1] ) && file_exists ( $callback [1] )) {
    									require_once $callback [1];
    								}
    								if (is_callable ( $callback [0] )) {
    									$req = call_user_func ( $callback [0], $this, $req );
    								}
    							}
    						}
    						$this->update ( $req, $this->table );
    						if (! empty ( $this->callback ['AFTER_UPDATE'] )) {
    							foreach ( $this->callback ['AFTER_UPDATE'] as $callback ) {
    								if (isset ( $callback [1] ) && file_exists ( $callback [1] )) {
    									require_once $callback [1];
    								}
    								if (is_callable ( $callback [0] )) {
    									call_user_func ( $callback [0], $this, $req, $this->insetId );
    								}
    							}
    						}
    						$this->redirect ( "?" . http_build_query ( $queryString, '', '&' ) );
    					}
    					break;
    				default :
    					$action = $this->action;
    					break;
    			}

    شكرا

  2. السلام عليكم 

    لدي مشكلة في query أنها تأخذ وقت طويل للتنفيذ كل ما زاد حجم البيانات في الجدول أريد المساعدة في تحسين الكود

    تستخرج query جميع أنواع العملات وتقارن فرق بين سعر العملة بين اليوم وأمس 

    أريد تحويل استخراج الفرق عند إضافة سجل جديد على الجدول يعني عند القيام بعملية insert

    $rs = mysqli_query($con, "SELECT a.wdt_ID, a.item_type, a.selling_price, a.date_price 
                              FROM wpdatatable_21 a 
                              WHERE date_price IN (SELECT MAX(date_price) 
                                                   FROM  wpdatatable_21 
                                                   WHERE item_type=a.item_type
                                                  ) 
                                and a.selling_price > 0 
                              GROUP BY item_type");
    
    
      while($row = mysqli_fetch_object($rs))
     {
        $rs2 = mysqli_query($con, "SELECT selling_price 
                                   FROM wpdatatable_21 
                                   WHERE item_type='".$row->item_type."' 
                                     AND date_price < '".$row->date_price."' 
                                   order by date_price desc limit 1");
    
        if(mysqli_num_rows($rs2) > 0)
        {
            $row2 = mysqli_fetch_object($rs2);
            $price = $row2->selling_price;
        }
        else
        {
                        $price = 0;
    
        } 
       $dif=$row->selling_price - $price;
    
      if($dif > 0)
      {
        $status  = "up";
      }
      else if($dif < 0)
      {
       $status  = "down";
     }
     else if($dif == 0)
     {
      $status  ="fixed";
     }
    
    $row->item_type;
    $row->date_price;
    $status;
    $row->selling_price;
    
    }

     

×
×
  • أضف...