Page 1 of 1

Problems displaying list from array

Posted: Fri Sep 24, 2010 3:37 pm
by k33bz
Work in progress, but all is paying off. This is one of the few problems that are left. Picture of problem is below, followed by suspected code.

Image

Anyway I have took out ALL comments, except a few that I am not sure if should be there or not, more like different variables you could choose.
Took out alot of double spaces, and tried to go through and remove the stuff that is not applied to the problem at hand. Still over a 1000 lines of code. So I wont post that. However I am going to post these two snippets, since it seems to be directly involved. And if there is a fix I can try to apply to all of the ones similar to it.

/lib/forms.php line 5

Code: Select all

$form_months = array (1 => "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December");



/lib/forms.php lines 1108 - 1131

Code: Select all

case "month":

								if (($field["fields"]["month"]["empty"] == "true"))  {

									$months[0] = "--" ;

								}



								global $form_months;



								if (is_array($months))

									$formmonths = array_merge($months, $form_months);

								else

									$formmonths = $form_months;



								$current_field .= $html->FormSelect(

																		$field["name"]."_month" , 

																		$formmonths, 

																		$this->templates , 

																		"DateSelect", 

																		$month_selected,

																		array() , 

																		array("DISABLED" => ($field["fields"]["month"]["editable"] == "false") ? "DISABLED" : "")

																	);



								$current_field .= $val["separator"];

							break;
Now as far as numbers, like those for the dates and years, I cant seem to find a list defined like it was defined for months on line 5. Can those numbers be automated some how, if so how would that code look?

by the way, there is what appears to be a very big empty space, need to scroll all the way over to see it.

Re: Problems displaying list from array

Posted: Fri Sep 24, 2010 7:33 pm
by k33bz
Ok, I believe I grabbed the whole source where it is talking about dates. Some reason even talks about time, which I dont have available anyway on the site.
Still look above to see where it is defined on line 5

Code: Select all

case "date":



				if (is_array($field["fields"])) {



					echo "<pre style=\"background-color:white\">";

					print_r($field);

					print_r($values["values"]);



					$html = new CHtml;



					//do some variables cleaning

					if (is_array($years))

						unset($years);

					if (is_array($days))

						unset($days);

					if (is_array($months))

						unset($months);



					



					$date_vals = &$values["values"][$field["name"]];



					if ($date_vals > 1000) {



						//setting the previous values

						$year_selected = isset($values["values"][$field["name"] ."_year"]) ? $values["values"][$field["name"] ."_year"] : @date("Y" , $date_vals );

						$month_selected = isset($values["values"][$field["name"] ."_month"]) ? $values["values"][$field["name"] ."_month"] : @date("n" , $date_vals );

						$day_selected = isset($values["values"][$field["name"] ."_day"]) ? $values["values"][$field["name"] ."_day"] : @date("j" , $date_vals );



						//crap, adding the time values too

						$hour_selected = isset($values["values"][$field["name"] ."_hour"]) ? $values["values"][$field["name"] ."_hour"] : @date("G" , $date_vals );

						$minute_selected = isset($values["values"][$field["name"] ."_minute"]) ? $values["values"][$field["name"] ."_minute"] : @date("i" , $date_vals );

						$second_selected = isset($values["values"][$field["name"] ."_second"]) ? $values["values"][$field["name"] ."_second"] : @date("s" , $date_vals );

						

					} else {



						$fld = $field["fields"];



						//setting the default value 						

						$year_selected = $fld["year"]["default"] == "now" ? date("Y") : $fld["year"]["default"];

						$month_selected = $fld["month"]["default"] == "now" ? date("n") : $fld["month"]["default"];

						$day_selected = $fld["day"]["default"] == "now" ? date("j") : $fld["day"]["default"];



						//crap, adding the time values too

						$hour_selected = $fld["hour"]["default"] == "now" ? date("G") : $fld["hour"]["default"];

						$minute_selected = $fld["minute"]["default"] == "now" ? date("i") : $fld["minute"]["default"];

						$second_selected = $fld["second"]["default"] == "now" ? date("s") : $fld["second"]["default"];						

					}



					foreach ($field["fields"] as $key => $val) {

						switch ($key) {

							case "year":

								if ($field["fields"]["year"]["empty"] == "true") {

									$years[0] = "--" ;

								}

								

								for ($i = $field["fields"]["year"]["from"] ; $i <= $field["fields"]["year"]["to"] ; $i++ )

									$years[$i] = $i;									



								$current_field .= $html->FormSelect(

																		$field["name"]."_year" , 

																		$years , 

																		$this->templates , 

																		"DateSelect", 

																		$year_selected , 

																		array() , 

																		array("DISABLED" => ($field["fields"]["year"]["editable"] == "false") ? "DISABLED" : "")									

																	);



								$current_field .= $val["separator"];

							break;



							case "day":

								if ($field["fields"]["day"]["empty"] == "true") {

									$days[0] = "--" ;

								}



								for ($i = 1 ; $i <= 31 ; $i++ )

									$days[$i] = sprintf("%02d",$i);



								$current_field .= $html->FormSelect(

																		$field["name"]."_day" , 

																		$days , 

																		$this->templates , 

																		"DateSelect", 

																		$day_selected,

																		array() , 

																		array("DISABLED" => ($field["fields"]["day"]["editable"] == "false") ? "DISABLED" : "")

																	);

								$current_field .= $val["separator"];

							break;



							case "month":

								if (($field["fields"]["month"]["empty"] == "true"))  {

									$months[0] = "--" ;

								}



								//importing the months from global

								global $form_months;



								if (is_array($months))

									$formmonths = array_merge($months, $form_months);

								else

									$formmonths = $form_months;



								//ehcking if the dates must apear like strings or numbers

								$current_field .= $html->FormSelect(

																		$field["name"]."_month" , 

																		$formmonths, 

																		$this->templates , 

																		"DateSelect", 

																		$month_selected,

																		array() , 

																		array("DISABLED" => ($field["fields"]["month"]["editable"] == "false") ? "DISABLED" : "")

																	);



								$current_field .= $val["separator"];

							break;



							case "hour":

								for ($i = 0; $i <= 23; $i++ )

									$hours[$i] = sprintf("%02d",$i);;									



								$current_field .= $html->FormSelect(

																		$field["name"]."_hour" , 

																		$hours , 

																		$this->templates , 

																		"DateSelect", 

																		$hour_selected , 

																		array() , 

																		array("DISABLED" => ($field["fields"]["hour"]["editable"] == "false") ? "DISABLED" : "")									

																	);



								$current_field .= $val["separator"];

							break;



							case "minute":

								for ($i = 0; $i <= 59; $i++ )

									$minutes[$i] = sprintf("%02d",$i);;									



								$current_field .= $html->FormSelect(

																		$field["name"]."_minute" , 

																		$minutes , 

																		$this->templates , 

																		"DateSelect", 

																		$minute_selected , 

																		array() , 

																		array("DISABLED" => ($field["fields"]["minute"]["editable"] == "false") ? "DISABLED" : "")									

																	);



								$current_field .= $val["separator"];

							break;



							case "second":

								for ($i = 0; $i <= 59; $i++ )

									$seconds[$i] = sprintf("%02d",$i);;									



								$current_field .= $html->FormSelect(

																		$field["name"]."_second" , 

																		$seconds , 

																		$this->templates , 

																		"DateSelect", 

																		$second_selected , 

																		array() , 

																		array("DISABLED" => ($field["fields"]["minute"]["editable"] == "false") ? "DISABLED" : "")									

																	);



								$current_field .= $val["separator"];

							break;



						}						

					}					

				}				



				//if the field hs description then i add the valign code

				$current_field_extra = $field["description"] ? $this->templates->blocks["TopAlign"]->output : ""; 



			break;
oh, almost forgot, I took out the indexing from line 5, so instead of it starting out like
$form_months = array (1 => "January"
it is now starting out like
$form_months = array ( "January"