/* CSS Document */

/*Front color*/

.blue-dark {
	color: #1f3a75;
}

.blue-medium {
	color: #0d98d1;
}

.blue-light {
	color: #d5ecf5;
}

.red-dark {
	color: #741111;
}

.red-medium {
	color: #e72d37;
}

.green {
	color: #04ba05;
}

.green-md {
	color: #98ca40;
}

.gray-dark {
	color: #474b4d;
}

.gray-light {
	color: #a1a1a1;
}

.white {
	color: white;
}




/*BG color*/

.bg-blue-dark {
	background-color: #1f3a75;
}

.bg-blue-medium {
	background-color: #0d98d1;
}

.bg-blue-light {
	background-color: #d5ecf5;
}

.bg-red-dark {
	background-color: #741111;
}

.bg-red-medium {
	background-color: #e72d37;
}

.bg-green {
	background-color: #04ba05;
}

.bg-green-md {
	background-color: #98ca40;
}

.bg-green-light {
	background-color: #dff4af;
}


.bg-gray-dark {
	background-color: #474b4d;
}

.bg-gray-light {
	background-color: #a1a1a1;
}

.bg-white {
	background-color: #ffffff;
}

.bg-black-transparent-70 {
	background-color: #000000;
	opacity: 0.7;
    filter: alpha(opacity=70); /* For IE8 and earlier */
}

.bg-gradient-red {
	background-image: url(../img/bg-gradient-red.png);
	background-repeat: repeat-x;
}

.bg-gradient-green {
	background-image: url(../img/bg-gradient-green.png);	
	background-repeat: repeat-x;
    background-size: auto 100% ;
    
}nect to the database
			$connection = $this -> connect();

			// Query the database
			$result = $connection -> query($query);
			
			return $result;
		}
	   
	   
	   
	   
	   
		
		
		
		
		
		//------------------------------------------------------------------------------------------
		/* Fetch rows from the database (SELECT query)
		@param $query The query string
		@return bool False on failure / array Database rows on success */
		
		public function select($query) {
			$rows = array();
			$result = $this -> query($query);
			
			if($result === false) {
				return false;
			}
						
				  
			while ($row = $result -> fetch_assoc()) {
				$rows[] = $row;
			}
			
			if(count($rows[0]) == 0)
			   return false;
			
			return $rows;
		}

	   
	   
	   
	   

		
		
		
		
		
		//------------------------------------------------------------------------------------------
		/* Fetch the last error from the database
		@return string Database error message */
		
		public function error() {
			$connection = $this -> connect();
			return $connection -> error;
		}
	   
	   
	   
		
		
		
		
	   

		//------------------------------------------------------------------------------------------
		/* Quote and escape value for use in a database query
		@param string $value The value to be quoted and escaped
		@return string The quoted and escaped string */
		
		public function quote($value) {
			$connection = $this -> connect();
			return "'" . $connection -> real_escape_string($value) . "'";
		}
		
		
		
		
		
		
		
		
		
		
		//------------------------------------------------------------------------------------------
		public function truncateTable($DBTableName) {
			$result = $this -> query("truncate `".$DBTableName."`");	
			return $result;
		}
		
		
		
		
		
		
		
		
		
		
		//------------------------------------------------------------------------------------------
		public function saveArrayIntoTable($DBTableName, $XLS_Data, $RowStart = 1, $RowsToSave = 1, $Verbose = true) {

			$QueryFields = "";
			$QueryValues = "";
			$RowsTotal 	 = count($XLS_Data);
			
			if($RowStart == $RowsToSave) {
				$RowsEnd = $RowsTotal;
			} else {
				$RowsEnd 	 = $RowStart + $RowsToSave; 
			}
			
			
			
			for ($n = $RowStart; $n <= $RowsEnd; $n++) {
				
				if($n >= $RowsTotal) {
					if($Verbose == true)
						echo "$n. ---- EOF<br>";
					break;
				}
				
				$QueryFields = "";
				$QueryValues = "";
				$ColsCount = count($XLS_Data[$n]);
				

				for ($m = 0; $m < $ColsCount; $m++) {
					$QueryFields .= "`".$XLS_Data[0][$m]."`";
					if($m < ($ColsCount-1)) 
						$QueryFields .= ", ";
					
					$XLS_Data[$n][$m] = utf8_encode($XLS_Data[$n][$m]);
					$temp = mysqli_real_escape_string(self::$connection,$XLS_Data[$n][$m]);
					$QueryValues .= "'".$temp."'";
					if($m < ($ColsCount-1)) 
						$QueryValues .= ", ";

					//echo $XLS_Data[$n][$m].",";
				}
				//echo "<br>";



				// Insert the values into the database
				//if($Verbose == true)
				//	echo "INSERT INTO `".$DBTableName."` (".$QueryFields.") VALUES (".$QueryValues.")"."<br>";

				$result = $this -> query("INSERT INTO `".$DBTableName."` (".$QueryFields.") VALUES (".$QueryValues.")");		

				if($result === false) {
					if($Verbose == true)
						echo "$n. ERROR guardando tabla $DBTableName en base de datos. <br>";
					return false;
				}
				
				if($Verbose == true)
					echo "$n. Datos guardados en base de datos con éxito.<br>";
			
			} 
			
			return true;
			
		}
		
		
		
		
		
		
		
		
		
		
		//------------------------------------------------------------------------------------------
		public function prepareLatinString($Text) {
						
			$FinalText = utf8_encode($Text);
			$FinalText = mysqli_real_escape_string(self::$connection,$FinalText);
			
			return $FinalText;
		}
		
		
		
		
		
		
		//-----------------------------------------------------------------------------------------------------------
		public function dbUpdate($Table, $Vars, $Values, $ShowQuery=false)
		{
			//First array element is WHERE Key
			
			$String = "";

			for($n = 1; $n < count($Vars); $n++) {
				$String = $String."`".$Vars[$n]."` = '".$Values[$n]."',";
			}
			$String = rtrim($String, ',');


			$Query = "UPDATE `$Table` SET $String 
						 WHERE CONVERT( `$Table`.`$Vars[0]` USING utf8 ) = '$Values[0]' LIMIT 1 ";					 
			$Result = self::query($Query);
			
			if(!$Result) {
				exit("[ERROR] db-class>dbUpdate. Query=".$Query);
			}
			
			if($ShowQuery)
				echo "Query: $Query <br>";
			
			return $Result;

		}
		
		
		
		
		//-----------------------------------------------------------------------------------------------------------
		public function dbInsert($db, $Table, $Vars, $Values)
		{

			$StringVars = "";

			for($n = 0; $n < count($Vars); $n++) {
				$StringVars = $StringVars."`".$Vars[$n]."` ,";
			}
			$StringVars = rtrim($StringVars, ',');
			
			
			$StringValues = "";
			
			for($n = 0; $n < count($Values); $n++) {
				$StringValues = $StringValues."'".$Values[$n]."' ,";
			}
			$StringValues = rtrim($StringValues, ',');

			
	
			
			
			$Query = "INSERT INTO `$Table` ($StringVars) VALUES ($StringValues)";					 

			$Result = $db -> query($Query);
			
			if(!$Result) {
				exit("[ERROR] db-class>dbInsert. Query=".$Query);
			}
			
			return;

		}
		
		
		
		
		
		
		
		
		
		//-----------------------------------------------------------------------------------------------------------
		public function dbInsertArray($TableName, $Array, $ShowQuery=false)
		{
			//Works only with key=>value arrays
			//Only one row per array
			
			$StringVars = "";
			$StringValues = "";
			
			foreach($Array as $key => $value)
			{
				$StringVars = $StringVars."`".$key."` ,";
				$StringValues = $StringValues."'".$value."' ,";
			}
			
			$StringVars = rtrim($StringVars, ',');
			$StringValues = rtrim($StringValues, ',');
		
			$Query = "INSERT INTO `$TableName` ($StringVars) VALUES ($StringValues)";
			
			$Result = self::query($Query);
			
			if($ShowQuery)
				echo "Query: $Query <br>";
			
			return $Result;
		}
		
		
		
		
		
		
		
	} // End class


?>