chiron-gaming /include/setorder.php

Language PHP Lines 215
MD5 Hash 2e44cbb0015ea415a995250cab63a3cb Estimated Cost $3,505 (why?)
Repository https://bitbucket.org/itoxable/chiron-gaming.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?
//---------------------------Set Category Order when Insert--------------------------//           
  function setcatorderinsert($tablename="",$categoryid="",$categoryorder="",$orderno="",$lastorderno="")		  {
		   
		   $orderno = $orderno > $lastorderno ? $lastorderno : $orderno;   
	   
			$sql_ordering = "select $categoryid, $categoryorder from $tablename where $categoryorder >= '$orderno' order by $categoryorder asc";
			$sql_result = mysql_query($sql_ordering);

			$i=1;
			while($row_result=mysql_fetch_array($sql_result))
			{

			$new_category_order = $orderno + $i ;
	     	$sql_update_order = "update $tablename set $categoryorder = '$new_category_order' where $categoryid = '$row_result[$categoryid]'";
			mysql_query($sql_update_order);
			$i++; 

			}
      }
  
//-------------------------------------------------------------------------------------------------//


//---------------------------Set Category Order when Update--------------------------// 
function setcatorderupdate($tablename="",$categoryid="",$categoryorder="",$orderno="",$lastorderno="",$categoryidval="")		      
	   {
			$sql_last_ordering = "select * from $tablename where $categoryorder = '$orderno'";
			$last_cat_id = mysql_result(mysql_query($sql_last_ordering),0,0);

			$sql_upt_order = "UPDATE $tablename SET $categoryorder='$orderno'  WHERE $categoryid = '$categoryidval'";
			mysql_query($sql_upt_order) or die("1".mysql_error());

			$sql_upt_order1 = "UPDATE $tablename SET $categoryorder='$lastorderno'  WHERE $categoryid = '$last_cat_id'";
			mysql_query($sql_upt_order1) or die("2".mysql_error());

         }
 //-------------------------------------------------------------------------------------------------//

//----------------------Set Category Order when Delete--------------------------------------//	
		 
function setcatorderdelete($tablename="",$categoryid="",$categoryorder="",$orderno="",$lastorderno="",$categoryidval="")		   		      
       {  
		   $sql_order = "select $categoryorder from $tablename where $categoryid = '$categoryidval'";
		   $order_result = mysql_query($sql_order);

		   $row_order=mysql_fetch_array($order_result);
		   $category_order = $row_order[$categoryorder];
		   

		   $sql_ordering = "select $categoryid,$categoryorder from $tablename  where $categoryorder > '$category_order' order by $categoryorder asc";
		   $sql_result = mysql_query($sql_ordering);


		   while($row_result=mysql_fetch_array($sql_result))
		   {
			  $old_category_id = $row_result[$categoryid];
			  $old_category_order = $row_result[$categoryorder];
			  $new_category_order = $old_category_order - 1;
			  $sql_update_order = "update $tablename set $categoryorder = '$new_category_order' where $categoryid = '$old_category_id'";
			  mysql_query($sql_update_order);
		   }
		}
   	//----------------------------------------------------------------------------------------------//

 //----------------------Set SubCategory Order when Insert--------------------------------------//
  function  setsubcatorderinsert($tablename="",$subcategoryid="",$subcategoryorder="",$orderno="",$lastorderno="",$categoryid="",$categoryidval="")	
  {
	
	$sql_ordering = "select $subcategoryid, $subcategoryorder from $tablename where $subcategoryorder >= '$orderno' and $categoryid = '$categoryidval' order by $subcategoryorder asc";
	$sql_result = mysql_query($sql_ordering);
    
		while($row_result=mysql_fetch_array($sql_result))
		{
			$old_id = $row_result[$subcategoryid];
			$old_order = $row_result[$subcategoryorder];
			$new_order = $old_order + 1;
			$sql_update_order = "update $tablename set $subcategoryorder = '$new_order' where $subcategoryid = '$old_id' and $categoryid = '$categoryidval'";
			mysql_query($sql_update_order);
		}
  }

//-------------------------------------------------------------------------------------------------//
//----------------------Set SubCategory Order when Update--------------------------------------//
function setsubcatorderupdate($tablename="",$subcategoryid="",$subcategoryidval="",$subcategoryorder="",$orderno="",$lastorderno="",$categoryid="",$categoryidval="")	
		{
		$sql_last_ordering = "select * from $tablename where $subcategoryorder = '$orderno' and $categoryid = $categoryidval";
		$last_cat_id = mysql_result(mysql_query($sql_last_ordering),0,0);

		$sql_upt_order = "UPDATE $tablename SET $subcategoryorder='$orderno'  WHERE $subcategoryid = '$subcategoryidval' and $categoryid = $categoryidval";
		mysql_query($sql_upt_order) or die("1".mysql_error());

		$sql_upt_order1 = "UPDATE $tablename SET $subcategoryorder='$lastorderno'  WHERE $subcategoryid = '$last_cat_id' and $categoryid = $categoryidval";
		mysql_query($sql_upt_order1) or die("2".mysql_error());
		}


//-------------------------------------------------------------------------------------------------//
//------------------------- Set SubCategory Order when Changing Category ------------------------//
function setsubcatorderfixing($tablename="",$subcategoryid="",$categoryid="",$categoryidval="",$subcategoryorder="",$lastorderno="")	
{
	$sql_last_ordering = "select * from $tablename where $subcategoryorder > '$lastorderno' and $categoryid = $categoryidval";
	$rs_last_ordering = mysql_query($sql_last_ordering);
	if(mysql_num_rows($rs_last_ordering)>0){
		while($row_last_ordering=mysql_fetch_array($rs_last_ordering)) {
			$recordid = $row_last_ordering[$subcategoryid];
		
			$sql_upt_order = "UPDATE $tablename SET $subcategoryorder = $subcategoryorder - 1 WHERE $subcategoryid = '$recordid' and $categoryid = $categoryidval";
			mysql_query($sql_upt_order) or die("Ordering Failed".mysql_error());
		}
	}
	mysql_free_result($rs_last_ordering);
}


//-------------------------------------------------------------------------------------------------// 
//----------------------Set SubCategory Order when Delete--------------------------------------// 
 function setsubcatorderdelete($tablename="",$subcategoryid="",$subcategoryidval="",$subcategoryorder="",$orderno="",$lastorderno="",$categoryid="",$categoryidval="")	
   {
	  $sql_order = "select $subcategoryorder from $tablename where $subcategoryid = '$subcategoryidval' and $categoryid = $categoryidval";
	  $order_result = mysql_query($sql_order);

		   $row_order=mysql_fetch_array($order_result);
		   $order_no = $row_order[$subcategoryorder];
		   
		   $sql_ordering = "select $subcategoryid,$categoryid,$subcategoryorder from $tablename  where $subcategoryorder > '$order_no' and $categoryid = $categoryidval order by $subcategoryorder asc";
		   $sql_result = mysql_query($sql_ordering);


		   while($row_result=mysql_fetch_array($sql_result))
		   {
			  $old_id = $row_result[$subcategoryid];
			  $old_order = $row_result[$subcategoryorder];
			  $new_order = $old_order - 1;
			  $sql_update_order = "update $tablename set $subcategoryorder = '$new_order' where $subcategoryid = '$old_id'";
			  //echo "<br>";
			  mysql_query($sql_update_order);
		   }
    }
	
//----------------------Set SubCategory Order when Update When transfer--------------------------------------//
function setsubcatorderupdatetransfer($tablename,$subcategoryordername,$categoryidname,$currentcategoryidval,$subcategoryidname,$subcategoryidval)	
{
	$lastcategoryidval=mysql_result(mysql_query("SELECT $categoryidname FROM $tablename WHERE $subcategoryidname='$subcategoryidval'"),0,0);
					
	if($currentcategoryidval!=$lastcategoryidval)
	{
		$lastsubcategoryorder =mysql_result(mysql_query("SELECT $subcategoryordername FROM $tablename WHERE $subcategoryidname='$subcategoryidval'"),0,0);
		
		$selectsubcatorrderupdate="select * from $tablename where $categoryidname='$lastcategoryidval' and $subcategoryordername>$lastsubcategoryorder order by $subcategoryordername";
		$resultsubcatorrderupdate=mysql_query($selectsubcatorrderupdate);
		while($rowsubcatorrderupdate=mysql_fetch_array($resultsubcatorrderupdate))
		{
			$sql_update_order = "update $tablename set $subcategoryordername = $subcategoryordername-1 where $subcategoryidname = '".$rowsubcatorrderupdate[$subcategoryidname]."'";
			$result_update_order=mysql_query($sql_update_order);
		}
		$subcategoryorder = mysql_result(mysql_query("select ifnull(max($subcategoryordername)+1,1) from $tablename WHERE $categoryidname='$currentcategoryidval'"),0,0);
	}
	else
	{
		$subcategoryorder =mysql_result(mysql_query("SELECT $subcategoryordername FROM $tablename WHERE $subcategoryidname='$subcategoryidval'"),0,0);
	}	
	return $subcategoryorder;
}


//-------------------------------------------------------------------------------------------------//	


// ================================================================================================= //
// 					Function to Re_order all the Display ordering [Start]							 //
// ================================================================================================= //

	function rearrangeOrder($tablename="",$fieldId="",$parentId="",$fieldOrder="",$orderno="",$lastorderno="",$fieldIdVal="",$parent_id="")  
    {  
	   $sql_order = "select $fieldOrder from $tablename where $fieldId = '$fieldIdVal'";
	   $order_result = mysql_query($sql_order);

	   $row_order=mysql_fetch_array($order_result);
	   $category_order = $row_order[$fieldOrder];
	   
		if($parentId != "" && $parent_id != "")
		{
	   		$sql_ordering = "select $fieldId,$fieldOrder 
								from $tablename  
								where $fieldOrder > '$category_order' 
								and $parentId = '$parent_id'
								order by $fieldOrder asc";
		}
		else
		{
			$sql_ordering = "select $fieldId,$fieldOrder 
								from $tablename  
								where $fieldOrder > '$category_order' 
								order by $fieldOrder asc";
		}
	   $sql_result = mysql_query($sql_ordering);


	   while($row_result=mysql_fetch_array($sql_result))
	   {
		  $old_category_id = $row_result[$fieldId];
		  $old_category_order = $row_result[$fieldOrder];
		  $new_category_order = $old_category_order - 1;
		  $sql_update_order = "update $tablename set $fieldOrder = '$new_category_order' where $fieldId = '$old_category_id'";
		  mysql_query($sql_update_order);
	   }
	}

// ================================================================================================= //
// 					Function to Re_order all the Display ordering [End]								 //
// ================================================================================================= //


?>
Back to Top