浏览代码

Don't display an error (assertion failed) if the user selects nothing (i.e -- select one --) in the "CSV template" tab.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1394 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 年之前
父节点
当前提交
9f6bc69fd6
共有 1 个文件被更改,包括 23 次插入26 次删除
  1. 23 26
      pages/ajax.csvimport.php

+ 23 - 26
pages/ajax.csvimport.php

@@ -374,37 +374,34 @@ EOF
 
 		case 'get_csv_template':
 		$sClassName = utils::ReadParam('class_name');
-		$oSearch = new DBObjectSearch($sClassName);
-		$oSearch->AddCondition('id', 0, '='); // Make sure we create an empty set
-		$oSet = new CMDBObjectSet($oSearch);
-		$sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true));
-		//$aCSV = explode("\n", $sCSV);
-		// If there are more than one line, let's assume that the first line is a comment and skip it.
-		//if (count($aCSV) > 1)
-		//{
-		//	$sResult = $aCSV[0];
-		//}
-		//else
-		//{
-		//	$sResult = $sCSV;
-		//}
-
-		$sClassDisplayName = MetaModel::GetName($sClassName);
-		$sDisposition = utils::ReadParam('disposition', 'inline');
-		if ($sDisposition == 'attachment')
+		if (MetaModel::IsValidClass($sClassName))
 		{
-			$oPage = new CSVPage("");
-			$oPage->add_header("Content-type: text/csv; charset=utf-8");
-			$oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\"");
-			$oPage->no_cache();		
-			$oPage->add($sResult);	
+			$oSearch = new DBObjectSearch($sClassName);
+			$oSearch->AddCondition('id', 0, '='); // Make sure we create an empty set
+			$oSet = new CMDBObjectSet($oSearch);
+			$sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true));
+	
+			$sClassDisplayName = MetaModel::GetName($sClassName);
+			$sDisposition = utils::ReadParam('disposition', 'inline');
+			if ($sDisposition == 'attachment')
+			{
+				$oPage = new CSVPage("");
+				$oPage->add_header("Content-type: text/csv; charset=utf-8");
+				$oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\"");
+				$oPage->no_cache();		
+				$oPage->add($sResult);	
+			}
+			else
+			{
+				$oPage = new ajax_page("");
+				$oPage->no_cache();
+				$oPage->add('<p style="text-align:center"><a style="text-decoration:none" href="'.utils::GetAbsoluteUrlAppRoot().'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&class_name='.$sClassName.'"><img border="0" src="../images/csv.png"><br/>'.$sClassDisplayName.'.csv</a></p>');		
+				$oPage->add('<p><textarea rows="5" cols="100">'.$sResult.'</textarea></p>');
+			}		
 		}
 		else
 		{
 			$oPage = new ajax_page("");
-			$oPage->no_cache();
-			$oPage->add('<p style="text-align:center"><a style="text-decoration:none" href="'.utils::GetAbsoluteUrlAppRoot().'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&class_name='.$sClassName.'"><img border="0" src="../images/csv.png"><br/>'.$sClassDisplayName.'.csv</a></p>');		
-			$oPage->add('<p><textarea rows="5" cols="100">'.$sResult.'</textarea></p>');
 		}
 		break;
 	}