<commit_before><!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Test iConneqt API</title>
		<link href='../common.css' rel="stylesheet" type='text/css'/>
    </head>
    <body>
		<?php
		/**
		 * This example demonstrates a simple subscription form with partial
		 * discovery of list and field information.
		 * If you already know all the ID's, you can hardcode them if you want.
		 * Alternatively, you can use the names of the fields instead of the
		 * ID's when adding a subscriber.
		 */
		require_once '../common.php';

		$iconneqt = new Iconneqt\Api\Rest\Iconneqt(ICONNEQT_URL, ICONNEQT_USERNAME, ICONNEQT_PASSWORD);

		define('EXAMPLE_LISTID', 92); // This should be a user setting

		if (isset($_POST['addSubscriber'])) {
			
			$fields = [];
			foreach ($_POST as $key => $value) {
				if (is_int($key)) {
					$fields[$key] = $value;
				}
			}
			
			try {
				$list = $iconneqt->getList(EXAMPLE_LISTID);
				$subscriber = $list->addSubscriber($_POST['email'], true, $fields);
				echo "<div class='success'>Added subscriber #{$subscriber->getId()}</div>";
			} catch (Exception $e) {
				echo "<div class='error'>Could not add subscriber: {$e->getCode()} {$e->getMessage()}</div>";
			}
		}
		?>

		<h1>Lists</h1>
		<ol>
		<?php
		foreach ($iconneqt->getLists() as $list) {
			echo "<li>List '{$list->getName()}' (#{$list->getId()}) has {$list->getFieldCount()} fields and {$list->getSubscriberCount()} subscribers.</li>";

			echo "<ol>";
			foreach ($list->getSubscribers() as $subscriber) {
				echo "<li>{$subscriber->getEmail()} (#{$subscriber->getId()})</li>";

				echo "<ul>";
				foreach ($subscriber->getFields() as $field) {
					echo "<li>{$field->getName()}: {$field->getValue()}</li>";
				}
				echo "</ul>";
			}
			echo "</ol>";
		}
		?>
		</ol>

		<hr/>

		<h1>Add subscriber to list #92</h1>
		<form method='post'>
			<div><label>E-mail address</label><input name='email' placeholder='<EMAIL>'/></div>
			<?php
			foreach ($iconneqt->getListFields(EXAMPLE_LISTID) as $field) {
				switch ($field->getType()) {<commit_msg>Fully utilize field roles<commit_after><!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Test iConneqt API</title>
		<link href='../common.css' rel="stylesheet" type='text/css'/>
    </head>
    <body>
		<?php
		/**
		 * This example demonstrates a simple subscription form with partial
		 * discovery of list and field information.
		 * If you already know all the ID's, you can hardcode them if you want.
		 * Alternatively, you can use the names of the fields instead of the
		 * ID's when adding a subscriber.
		 */
		require_once '../common.php';

		$iconneqt = new Iconneqt\Api\Rest\Iconneqt(ICONNEQT_URL, ICONNEQT_USERNAME, ICONNEQT_PASSWORD);

		define('EXAMPLE_LISTID', 92); // This should be a user setting

		if (isset($_POST['addSubscriber'])) {
			
			$fields = [];
			foreach ($_POST as $key => $value) {
				if (is_int($key)) {
					$fields[$key] = $value;
				}
			}
			
			try {
				$list = $iconneqt->getList(EXAMPLE_LISTID);
				$subscriber = $list->addSubscriber($_POST['email'], true, $fields);
				echo "<div class='success'>Added subscriber #{$subscriber->getId()}</div>";
			} catch (Exception $e) {
				echo "<div class='error'>Could not add subscriber: {$e->getCode()} {$e->getMessage()}</div>";
			}
		}
		?>

		<h1>Lists</h1>
		<ol>
		<?php
		foreach ($iconneqt->getLists() as $list) {
			echo "<li>List '{$list->getName()}' (#{$list->getId()}) has {$list->getFieldCount()} fields and {$list->getSubscriberCount()} subscribers.</li>";

			echo "<ol>";
			foreach ($list->getSubscribers() as $subscriber) {
				echo "<li>{$subscriber->getEmail()} (#{$subscriber->getId()})</li>";

				echo "<ul>";
				foreach ($subscriber->getFields() as $field) {
					echo "<li>{$field->getName()}: {$field->getValue()}</li>";
				}
				echo "</ul>";
			}
			echo "</ol>";
		}
		?>
		</ol>

		<hr/>

		<h1>Add subscriber to list #92</h1>
		<form method='post'>
			<div><label>E-mail address</label><input name='email' placeholder='<EMAIL>'/></div>
			<?php
			// Get all* fields (* = first 100)
			$fields = $iconneqt->getListFields(EXAMPLE_LISTID);
			
			// List of roles to use
			$roles = array(
				'namefirst',
				'namelast',
			);
			
			// Remove any fields that do not have a role that we want to use
			$fields = array_filter($fields, function($field) use($roles) {
				return in_array($field->getRole(), $roles);
			});
			
			// Sort fields by the order or roles
			uasort($fields, function($a, $b) use($roles) {
				return array_search($a->getRole(), $roles) - array_search($b->getRole(), $roles);
			});
			
			// Display the fields
			foreach ($fields as $field) {
				switch ($field->getType()) {
{'fraction_non_alphanumeric': 0.19401096583719948, 'fraction_numerical': 0.004428511176718684, 'mean_word_length': 3.3835489833641406, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 122, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7623698', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1576, 'n_words': 401}